- 博客(57)
- 收藏
- 关注
原创 我与C++一起度过的日子
转眼间,大一就要过去了,记得刚开始的时候,我连什么C++, java 。。的都不知道,而现在都可以自己编一些小的程序(当然也是一些菜鸟级别的)了,想想就兴奋。感觉自己满有成就感的,回家的时候可以和自己的朋友吹牛皮了。。。 最重要的是感谢贺老师,老师交给我们用博文提交程序(这是第一次用,老师居然把我们当试验品。。。),让我们写的程序,可以让更多的人看到,让更多的人认识我们, 还可以浏览高手的博
2012-06-11 19:23:17
1049
3
原创 第十七周实验报告1
文件的二进制输入; #include #include #include #include using namespace std; class Student { private: string name; float Cscore; float Mathscore; float Englishscore; float score; float Ae
2012-06-11 18:55:37
2698
原创 第十六周实验报告4
【任务4】文档的自动处理 #include #include //#include using namespace std; int main() { ifstream readfile; ofstream writefile; char ch[100]; int i; readfile.open("WolfSheep.nls", ios::in);
2012-06-06 13:14:00
1162
原创 第十六周实验报告2
作品名:学生成绩 #include #include #include #include using namespace std; class Student { private: string name; float Cscore; float Mscore; float Escore; float Tscore; float Ascore; public: Stude
2012-06-04 20:26:18
755
原创 十六周实验报告1
#include #include using namespace std; int main() { float salary[500], t; int i, j, m; ifstream readFile("salary.txt",ios::in); if(! readFile) { cerr << "open error!" << endl; exit(1);
2012-06-04 20:21:29
881
原创 第十六周实验报告3
作品名:电子词典 英文、中文释义与词性间用’\t’隔开。建一个表示词条的类Word,Word 类的一个对象可以描述一个词, 类对象数组可以存储词库。将文件中的内容读到对象数组中,由用户输入英文词,显示中文释义。 允许用户运行程序后,连续地查词典,直到输入”0000”结束 * 程序头部的注释结束 #include
2012-06-04 19:22:35
596
原创 第十五实验报告1
头文件 class Triangle { public: Triangle(){a = 1; b = 1; c = 1;} Triangle(double x, double y, double z) {a = x; b = y; c = z;} double area(); double permeter(); private: double a, b, c; }; 源
2012-05-30 22:43:39
805
原创 第十五周实验报告3
#include using namespace std; int main() { int a; cout<<"input a:"; cin>>a; cout<<"dec:"<<dec<<a<<endl; //以十进制输出 cout<<"hex:"<<hex<<a<<endl; //以十六进制输出 cout<<"oct:"<<setbase(8)<<a<<endl; //以
2012-05-30 22:29:15
759
原创 第十五周实验报告2
头文件 class CFraction { private: int nume; int deno; public: CFraction(int n=0, int d=1) : nume(n), deno(d){} CFraction shuanfa(CFraction &a, CString &m); friend CFraction simple( CFraction &cf);
2012-05-30 22:23:42
862
原创 第十四周实验报告1
#include using namespace std; class MyArray { private: int *arr; //用于存放动态分配的数组内存首地址 int size; //数组大小 public: MyArray(int sz=50); MyArray(int a[],int sz); //由一个内置类型的数组初始化 MyArray(const MyArray
2012-05-25 15:00:48
797
2
原创 第十四周实验报告2
#include using namespace std; class Student { public: Student(int n,double s){num=n;score=s;next=NULL;} Student *next; int num; double score; }; class MyList
2012-05-23 12:49:13
554
原创 第十三周实验报告4
【任务4】设计一个抽象类CSolid,含有两个求表面积及体积的纯虚函数。设计个派生类CCube、CBall、CCylinder,分别表示正方体、球体及圆柱体。在main()函数中,定义基类的指针p(CSolid *p;),利用p指针,输出正方体、球体及圆柱体对象的表面积及体积。 #include #define PI 3.1415 using namespace std; class C
2012-05-13 11:10:05
964
1
原创 第十三周实验报告3
【任务3】写一个程序,定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的mian()函数,求出定义的几个几何体的面积和。 #include #define PI 3.1415 using namespace std; class Shape { protected: public: virtual doub
2012-05-13 11:08:05
1221
1
原创 第十三周实验报告2
(任务2.1)根据main()函数给出的注释提示,设计出相关的各个类。 (任务2.2)显然,Animal设计为抽象类更合适,Animal不需要能够实例化,是专门作基类使用的。改造程序,使Animal设计为抽象类,这时main()函数中p = new Animal();将出错,将此行删除。 (任务2.3)每一个Animal的派生类都有一个“名字”数据成员,改造上面的程序,将这一数据成员作为抽象类
2012-05-13 11:05:23
606
原创 第十三周实验报告1
第13周实验指导 【目的】 1. 进一步多态性的基本概念 2. 学会利用虚函数实现多态性 3. 学会在设计中利用纯虚函数构造抽象基类 纯虚数 #include using namespace std; class Vehicle { public: virtual void run()const =0; //(2) run()为虚函数 }; class Car: p
2012-05-13 10:59:13
542
原创 第十二周实验报告4
#include #include #include using namespace std; class Point { public: Point(){x = 0; y = 0;} Point(double x0,double y0) {x = x0; y = y0;} ~Point(){} double getx(){return x;} double gety(){re
2012-05-09 19:55:14
883
1
原创 第十二周实验报告3
#include #include #include using namespace std; enum vehicleStaus {rest, running}; //车辆状态:泊车、行进 class vehicle //车辆类 { protected: int maxSpeed; //最大车速 int currentSpeed; //当前速度 int weight; //车重
2012-05-09 19:51:56
1251
原创 第十周实验报告2
#include #include using namespace std; class Teacher { public: Teacher( string nam, int ag, char s, string addr, string tel, string ti); void display(); ~Teacher(){} private: string na
2012-05-08 21:36:46
356
原创 第十二周实验报告1
#include 07. 08.#include 09. 10.using namespace std; 11. 12.class Student //(1)修改student类中各数据成员和成员函数的访问限定符,并观察发生的现象 13.{ 14.public: 15. Student(int n, string nam, cha
2012-05-08 21:33:42
378
原创 第十周实验报告3
(1)先建立一个Point(点)类,包含数据成员x,y(坐标点); (2)以Point为基类,派生出一个Circle(圆)类,增加数据成员 (半径); (3)再以Circle类为直接基类,派生出一个Cylinder(圆柱体)类,再增加数据成员h(高)。要求编写程序,设计出各类中基本的成员函数(包括构造函数、析构函数、修改数据成员和获取数据成员的公共接口、用于输出的重载运算符“ #includ
2012-04-23 18:35:31
467
原创 第十周实验报告2
#include #include #include //setw:设置输出数据的宽度,使用时应#include using namespace std; class CPerson { protected: char *m_szName; char *m_szId; int m_nSex;//0:women,1:man int m_nAge; public
2012-04-23 18:10:42
1112
1
原创 第十周实验报告1
#include #include using namespace std; class Point //定义坐标点类 {public: int x,y; //点的横坐标和纵坐标 Point(){x=0;y=0;} Point(int x0,int y0) {x=x0; y=y0;} void PrintP(){cout<<"Point:("<<x<<","<<y<<
2012-04-23 18:04:39
409
原创 第八周实验报告4
在任务3的基础上拓展。分数类中的对象可以和整型数进行四则运算,且运算符合交换律。 例如:CFraction a(1,3),b; int i=2; 可以完成b=a+i;。同样,可以完成i+a, 45+a, a*27, 5/a等各种运算。 #include #include using namespace std; class CFraction { private: int num
2012-04-17 14:17:37
384
原创 第九周实验报告5
【任务5】设计一元一次方程类,求形如ax+b=0的方程的解。 例如:输入3x-8=0时,输出的方程的解为x=2.66667; 再如:输入5s+18=0时,输出的方程的解为s=-3.6; #include "iostream" using namespace std; class CEquation { private: double a; // 未知数系数 doubl
2012-04-17 14:16:13
361
原创 第九周实验报告4
建立一个二维数组类Douary,使该类中有以下数据成员、成员函数及友员函数,完成矩阵的输入、输出、加、减、相等判断等操作。#include using namespace std; class Douary { public: Douary(int m, int n);//构造函数:用于建立动态数组存放m行n列的二维数组(矩阵)元素,并将该数组元素初始化为 ~Douary();
2012-04-17 14:14:35
372
原创 第九周实验报告3
定义分数类中>运算符重载,实现分数的输入输出,改造原程序中对运算结果显示方式,使程序读起来更自然。 #include #include using namespace std; class CFraction { private: int nume; int deno; public: CFraction(int n=0, int d=1) : nume(n), deno
2012-04-17 14:05:14
292
原创 第九周实验报告2
#include using namespace std; class CTime { private: unsigned short int hour; // 时 unsigned short int minute; // 分 unsigned short int second; // 秒 public: CTime(int h=0,int m=0,int
2012-04-17 14:02:08
285
原创 第九周实验报告1
#include using namespace std; class Complex { public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r;imag=i;} Complex operator+(Complex &c2); Complex operator-(Complex &c2);
2012-04-17 14:01:03
296
原创 第八周实验报告3
实现分数类中的运算符重载,在分数类中可以完成分数的加减乘除(运算后再化简)、求反、比较(6种关系)的运算。 #include #include using namespace std; class CFraction { private: int nume; int deno; public: CFraction(int n=0, int d=1) : nume(n),
2012-04-10 13:38:58
360
原创 第八周实验报告2
【任务2】实现Time类中的运算符重载 #include using namespace std; class CTime { private: unsigned short int hour; // 时 unsigned short int minute; // 分 unsigned short int second; // 秒 public:
2012-04-10 13:36:20
490
1
原创 第八周试探报告1-3
3)方案三:在方案二的基础上,扩展+、-、*、/运算符的功能,使之能与double型数据进行运算。 设Complex c; double d; c?d和d?c的结果为将d视为实部为d的复数同c运算的结果(其中?为+、-、*、/之一)。 另外,定义一目运算符-,-c相当于0-c。 #include using namespace std; class Complex { p
2012-04-10 13:33:59
379
原创 第八周实验报告1-2
2)方案二:请用类的友元函数,而不是成员函数,完成上面提及的运算符的重载; #include using namespace std; class Complex { public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r;imag=i;} friend Complex operator+
2012-04-10 13:32:28
431
原创 第八周实验报告1-1
【任务1】实现复数类中的运算符重载定义一个复数类重载运算符+、-、*、/,使之能用于复数的加减乘除。 (1)方案一:请用类的成员函数完成运算符的重载; #include using namespace std; class Complex { public: Complex(){real=0;imag=0;} Complex(double r,double i){real
2012-04-10 13:30:22
429
原创 第七周实验报告3-2
#include using namespace std; template class Complex { public: Complex( ){real=0;imag=0;} Complex(numtype r,numtype i){real=r;imag=i;} Complex complex_add(Complex &); Complex c
2012-04-03 12:05:57
344
原创 第七周实验报告3-1
#include using namespace std; template class Complex { public: Complex( ){real=0;imag=0;} Complex(numtype r,numtype i){real=r;imag=i;} Complex complex_add(Complex &); void d
2012-04-03 12:01:41
357
原创 第七周实验报告2
#include #include using namespace std; class CPoint {private: double x; // 横坐标 double y; // 纵坐标 public: CPoint(double xx=0,double yy=0):x(xx),y(yy){} double atob(CPo
2012-04-03 11:58:30
712
1
原创 第七周实验报告1
#include using namespace std; class Time { public: Time(int=0,int=0,int=0); void show_time( ); //根据is_24和from0,输出适合形式-20:23:5/8:23:5 pm/08:23:05 pm void add_seconds(int); //增加n秒钟 void
2012-04-03 11:55:56
579
1
原创 第六周实验报告4
#include using namespace std; #include class CPoint { private: double x; // 横坐标 double y; // 纵坐标 public: CPoint(double xx=0,double yy=0); double Distance(CPoint p) const; // 两
2012-03-28 21:28:19
341
原创 第六周实验报告3
#include using namespace std; #include enum SymmetricStyle { axisx,axisy,point};//分别表示按x轴, y轴, 原点对称 class CPoint { private: double x; // 横坐标 double y; // 纵坐标 public: CPoint(double
2012-03-28 21:23:23
300
原创 第六周实验报告2
#include using namespace std; class A { private: int *a; int n; int MaxLen; public: A(int *, int , int ); A(): a(0), n(0), MaxLen(0) {} ~A(); int GetValue(int i) {return a
2012-03-28 21:17:02
316
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人