山大c++实验
没啥说的
Capsfly
这个作者很懒,什么都没留下…
展开
-
实验E6:设计一个有理数Rational类(构造和析构函数)
declare.h#pragma once#include <string>using namespace std;class Rational;int gcd(int a, int b);void find_true(int& a, int& b);int find_cnt();function.h#ifndef MAIN_CPP_HEAD_H#define MAIN_CPP_HEAD_H#include "declare.h"extern in.原创 2021-07-02 18:41:33 · 606 阅读 · 0 评论 -
实验E5:设计一个矩形类(类的设计)
declare.h#pragma onceclass Point;class line;class Rectangle;Rectangle.h#pragma once#include <iostream>#include <algorithm>using namespace std;class Point { double x, y;public: Point(double px = 0, double py = 0) { .原创 2021-07-02 18:38:22 · 386 阅读 · 0 评论 -
实验E4:对字符串的操作(函数接口设计、字符串操作)
#include <iostream>using namespace std;int size(char*path);//计算路径长度 char* filename(char*path);//获取文件名 char* filepath(char *path);//获取文件所在目录 char* refilecata(char*orig,char*now);//替换文件目录 orig是原来的文件路径,now是要替换成的目录 char* connect(char*cata,char*f.原创 2021-07-02 18:35:59 · 81 阅读 · 0 评论 -
实验E3:设计一个表示二维大小的矩阵 (函数接口设计、指针、数组)
#include <iostream>#include <cstdlib>#include <time.h>#include <string.h>using namespace std;void newmartix(int **&p,int row,int col);void averow( int **&martix,int row,int col,double sum[]);//计算row的平均值 void avecol( .原创 2021-07-02 18:20:12 · 200 阅读 · 0 评论 -
实验E2:模块化,接口与实现分离、多文件编译
array.h#include <iostream>#include <cstdlib>#include <string.h>using namespace std;#include <iostream>#include <cstdlib>#include <string.h>using namespace std;void set(int *arr,int size,int val=0);//设置初始值 .原创 2021-07-02 18:18:25 · 128 阅读 · 0 评论 -
实验E1:命令行工具fcmd,实验对文本的操作
fcmd.h#pragma once#include <string>void print(const std::string& filename);void format(const std::string& filename);void addWord(const std::string& filename);fcmd.cpp#include "fcmd.h"#include <fstream>#include <iostr原创 2021-07-02 18:14:28 · 222 阅读 · 0 评论 -
实验E12:验证类构造的顺序
#include <iostream>using namespace std;//单继承class Base { int x; int y;public: Base(int tox, int toy) :x(tox), y(toy) { cout << "constructing Base" << endl; } ~Base() { cout << "deconstructing.原创 2021-07-02 18:10:38 · 61 阅读 · 0 评论 -
实验E13:虚函数与运行时多态
#include<iostream>#include<vector>#include<fstream>#include<sstream>using namespace std;class StrHandler{protected: vector<char>storage_ch;public: StrHandler() {} virtual ~StrHandler() {} virtual voi.原创 2021-07-02 18:08:49 · 74 阅读 · 0 评论 -
实验E14:输入输出流
#include<iostream>#include<fstream>#include<iomanip>#include<sstream>#include<strstream>using namespace std;void String_stream_test(){ cout << "以下为字符串输入输出流和基本数据类型的转化" << endl; char str[] = " 12 3 .原创 2021-07-02 18:07:37 · 137 阅读 · 1 评论 -
实验E11 :验证各种继承情况下对象的构造和析构
#include <iostream>using namespace std;//单继承class Base { int x; int y;public: Base(int tox, int toy) :x(tox), y(toy) { cout << "constructing Base" << endl; } ~Base() { cout << "deconstructing.原创 2021-06-04 20:48:00 · 53 阅读 · 0 评论 -
实验E10:强制类型转化、类成员指针(static_cast, const_cas,t reinterpret_cast的使用)
#include <iostream>using namespace std;class base {public: int _val = 0; string name = "name"; int _num = 5; bool _jud = true; base() {} base(int toval) { _val = toval; } void show() const { .原创 2021-06-03 23:41:01 · 99 阅读 · 0 评论 -
不存在的E11:C++ 手写string及注意事项
手写string时候发现了一个问题,就是怎么进行这个操作,因为实现输入的数据量是不确定的。然后上网查了一下博客,发现一个合适的都没有,比如下面这个开了一个100的数组,那我直接输入一个1e5的量,不是直接爆炸吗。后来想到了解决方案,每次都是一个一个字符读,然后重载+=运算符。代码如下:#pragma once#include <cmath>#include <iostream>#include<assert.h>using namespace std原创 2021-05-03 15:58:59 · 106 阅读 · 1 评论 -
E9手写Vector和注意事项
本来写了一个还可以版本的Vector,然后改了一下用迭代器,然后就从2点查到5点。。。。#pragma once#include <string.h>#include <assert.h>template<class T>class Vector { typedef T* iterator; iterator _begin, _final; int Capacity;public: Vector():_begin(nullptr),_final(nul原创 2021-05-01 17:19:39 · 151 阅读 · 1 评论 -
实验E8:运算符重载
Vec3.h#pragma once#include <iostream>#include <cmath>#include <cassert>using namespace std;class Vec3 { double x, y, z;public: Vec3(double x, double y, double z) :x(x), y(y), z(z) {} Vec3(){} ~Vec3(){} Vec3 ..原创 2021-05-18 17:14:23 · 134 阅读 · 0 评论