- 博客(11)
- 收藏
- 关注
原创 第八章实验3
编写一个程序,使用类模板对数组元素进行排序、倒置、查找和求和#include#includeusing namespace std;const int n=8;templateclass Array{public: Array(T *p) { set=p; } ~Array(){} void inversion();//倒置 T sum();//求和 void
2015-06-04 09:01:22 1371
原创 第八章实验2
编写一个求任意类型数组中最大值和最小值元素的程序,要求将求最大元素和最小元素的函数设计成函数模板#include#includeusing namespace std;const int n=5;templatet max(t p[],int n){ t max=p[0]; for(int j=1;j<n;j++) { if(p[j]>max) {
2015-06-04 08:58:12 1012
原创 第七章实验三
声明一个类complex,定义两个对象c1 和c2,定义友元函数运算符重载,定义成员函数print。#includeusing namespace std;class complex{public: complex(double r=0.0,double i=0.0) { real=r; imag=i; } friend complex operator +(complex&
2015-05-25 19:42:21 633
原创 第七章7.9和7.10
编一个程序,用成员函数和友元函数重载运算符“+”和“-”,将两个二维数组相加和相减。要求第一个二维数组的值由构造函数设置,另一个二维数组的值由键盘输入。#include#includeusing namespace std;const int vol=3;const int col=3;class demension{public: demension(){} demensio
2015-05-25 19:39:21 939
原创 第五章5.19
5.19设计一个虚基类base,包含姓名、年龄私有数据成员以及相关成员函数,由它派生出领导类leader包含职务和部门私有成员以及相关的成员函数;再有base派生出工程师类engieer,包含职称和专业私有数据成员以及相关成员函数;然后由leader和engieer派生出主任工程师类chairman。#include#includeusing namespace std;class base
2015-05-03 16:00:41 590 1
原创 第五章5.18
5.18编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称、部门。要求将编号、姓名和显示设计成一个类person,并作为学生数据操作类student和teacher的基类。#include#includeusing namespace std;class person{public: person(string i,string n)
2015-05-03 14:40:56 509 2
原创 第四章
4.声明一个student类,在该类中包括一个数据成员score、两个静态数据成员sum和count#include#includeusing namespace std;class student{public: student(float s); static float sum(student &stu); static float average(studen
2015-04-28 19:57:24 1621 1
原创 前四章——老师类与学生类
#include#include#includeusing namespace std;class student{ friend class teacher;public: student( string name1,long n) { num=n; name=name1; english=0.0; math=0.0; } void show() {
2015-04-21 21:19:53 856 1
原创 c++面向对象的程序设计4*4的魔方程序
#include#includeusing namespace std;class magic{public: void getdate(); void setfirstmagic(); void generatemagic(); void printmagic();private: int m[4][4]; int step; int first; int sum;}
2015-04-07 23:12:36 4312 1
原创 c++面向对象程序设计第二章
2.29编写一个c++语言风格的程序,用动态分配空间的方法计算fibonacci数列的前20项并储到动态分配的空间中#include#includeusing namespace std;int main(){ int *fb; fb=new int[20]; fb[1]=fb[0]=1; int *i; i=new int; *i=2; for(*i=2;*i<20
2015-04-07 23:04:23 1183 1
原创 c++面向对象的程序设计第三章
3.22声明一个circle类。数据成员radius和数据函数area()。#includeusing namespace std;class cired{public: cired (int r) { radius=r; } void area() { int x=3*radius*radius; cout<<"半径为"<<radius<<"的圆的面积是
2015-03-29 10:09:54 916 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人