面向对象程序设计c实验报告_(编辑修改稿)内容摘要:
地址 student 类增加两个静态成员,人数( count)和平均分( average)。 注意构造函数、析构函数的编写以及静态成员的初始化,并说明这两个成员设置为静态成员的原因。 include iostream include string using namespace std。 class student { private: int sno。 char *name。 int age。 int score。 static int count。 static float average。 static float sum。 public: void input() { cinsnonameagescore。 } void print() { cout学号 snoendl。 cout姓名 nameendl。 cout年龄 ageendl。 cout分数 scoreendl。 } void show() { cout学生人数 :count。 cout平均成绩 :averageendl。 } student(int snol,char *namel,int agel,int scorel) { sno=snol。 name=new char[strlen(namel)+1]。 strcpy(name,namel)。 age=agel。 score=scorel。 ++count。 sum=sum+score。 average=sum/count。 } ~student() { delete name。 count。 sum=sumscore。 } }。 int student::count=0。 float student::sum=。 float student::average=。 int main() student a1(1,小小 ,20,99)。 ()。 ()。 student a2(2,小江 ,12,100)。 ()。 ()。 student a3(3,肖肖 ,21,89)。 ()。 ()。 return 0。 } count 随着定义对象的增加而增加。 每定义一个对象, count 加 1,累计学生人数, average也应该随着定义对象的增加而改变着。 因此它们被声明为静态数据成员,被 studengt 类的对象所共享。 output,实现和成员函数 print 相同的功能。 说明友元函数作用以及和成员函数的区别。 include iostream include string using namespace std。 class student { private: int sno。 string name。 int age。 int score。 public: void input() { cinsnonameagescore。 } friend void output(student amp。 )。 void print() { cout学号 snoendl。 cout姓名 nameendl。 cout年龄 ageendl。 cout分数 scoreendl。 } }。 void output(student amp。 p) { cout学号 姓名 endl。 cout年龄 分数 endl。 } int main() { student k[10]。 int i。 for(i=0。 i=9。 i++) { k[i].input()。 output(k[i])。 } } 友员函数可以通过入口参数传递进来的对象名(或对象指针、对象引用)来访问该对象所有的的数据成员,提高了程序运行效率。 没有友员机制,外部函数访问类的私有数据,必须调用公有成员函数,在需要频繁调用私有数据时,会带来很大的开销,降低程序运行效率。 实验五 派生类与继承 院(系): 课程名称: 面向对象程序设计 教师签名: 班级 学号 实验室 姓名 实验成绩 所用软件 Word 文档 、 VC++软件 实验目的和要求 1 理解类的继承的概念,能够定义和使用类的继承关系。 实验内容 1. 定义一个基类 MyArray,基类中可以存放一组整数。 class MyArray{ public: MyArray(int leng)。 ~MyArray()。 void Input()。 void Display()。 protected: int *alist。 //指向动态申请的一组空间 int length。 //整数的个数 }。 基类中有构造函数、析构函数、输入数据和输出数据的函数。 include class MyArray{ public: MyArray(int leng)。 ~MyArray()。 void Input()。 void Display()。 protected: int *alist。 //指向动态申请的一组空间 int length。 //整数的个数 }。 MyArray::MyArray(int leng) { alist=new int[leng]。 length=leng。 } MyArray::~MyArray() { delete []alist。 cout显示调用了析构函数 endl。 } void MyArray::Input() { int i。 cout请输入数组元素: endl。 for(i=0。 ilength。 i++) { cinalist[i]。 } } void MyArray::Display() { int j。 cout输出的数组元素为: endl。 for(j=0。 jlength。 j++) { coutalist[j]endl。 } } int main() { MyArray s(4)。 ()。 ()。 } 2. 定义一个类 SortArray 继承自 MyArray,在该类中定义函数实现排序功能。 includeiostream using namespace std。 class MyArray {public: MyArray(int leng) { length=leng。 alist=new int[length]。 } ~MyArray() {delete alist。 } void input() { int i。 for(i=0。 ilength。 i++) cinalist[i]。 } void display() { int j。 for(j=0。 jlength。 j++) coutalist[j]endl。 } protected: int *alist。 int length。 }。 class SortArray:public MyArray { public: SortArray(int leng):MyArray(leng) {} void pai() { int i。 int j。 int t。 for(i=0。 ilength。 i++) {for(j=i+1。 jlength。 j++) {if(alist[i]alist[j]) { t=alist[i]。 alist[i]=alist[j]。 alist[j]=t。 } } } for(i=0。 ilength。 i++) coutalist[i]。 } }。 int main() { int leng。 cinleng。 SortArray A(leng)。 ()。 ()。 ()。 return(0)。 } 3. 定义一个类 ReArray 继承自 MyArray,在该类中定义函数实现逆转功能。 includeiostream using namespace std。 class MyArray {public: MyArray(int leng) { length=leng。 alist=new int[length]。 } ~MyArray() {delete alist。 } void input() { int i。 for(i=0。 ilength。 i++) cinalist[i]。 } void display() { int j。 for(j=0。 jlength。 j++) coutalist[j]endl。 } protected: int *alist。 int length。 }。 class ReArray:public MyArray { public: ReArray(int leng):MyArray(leng) {} void nizhuan() { int j。 int t。 for(j=0。 jlength/2。 j++) { t=alist[j]。 alist[j]=alist[length1j]。 alist[lengthj1]=t。 } for(j=0。 jlength。 j++) {coutalist[j]。 } } }。 int main() { int leng。 cinleng。 ReArray A(leng)。 ()。 ()。 ()。 return(0)。 } 4. 定义一个类 AverArray 继承自 MyArray,在该类中定义函数 Aver 求解整数的平均值。 includeiostream using namespace std。 class MyArray {public: MyArray(int leng) { length=leng。 alist=new int[length]。 } ~MyArray() {delete alist。 } void input() { int i。 for(i=0。 ilength。 i++) cinalist[i]。 } void display() { int j。 for(j=0。 jlength。 j++) coutalist[j]endl。 } protected: int *alist。 int length。 }。 class AverArray:public MyArray { public: AverArray(int leng):MyArray(leng) {} void pingjun() { int j。 float sum。 float ave。 sum=。 for(j=0。 jlength。 j++) { sum+=alist[j]。 } ave=sum/length。 coutaveendl。 } }。 int main() { int leng。 cinleng。 AverArray A(leng)。面向对象程序设计c实验报告_(编辑修改稿)
相关推荐
8 3 . 6 01 2 1 2q l K N m 顶层短跨框架梁: 2211 1 0 . 9 5 2 . 7 6 . 6 51 2 1 2q l K N m 底层及标准层长跨框架梁: 2211 3 5 .5 5 6 . 6 1 2 9 .0 51 2 1 2q l K N m 16 底层及标准层长跨框架梁: 2211
接收)的功率或者场强随位置方向坐标的变化规律,并分别称为功率方向图和场方向图。 天线方向图是在远场区确定的,所以又叫远场方向图。 方向性函数绘制出的方向图称为归一化方向图,采用无量纲的相对值或分贝表示。 方向图有二维和三维方向图。 三维方向图分为球坐标三维方向图和直角坐标三维方向图,二维方向图分为极坐标方向图和直角坐标方向图两种。 南京工程学院毕业设计说明书(论文) 第 13 页 第 3 章
GCBO) eventdata 保留在 MATLAB 里面的参数,它的作用是方便后面的程序使用 handles GUI 界面的句柄,可以通过它获取整个界面的信息(详情请参见GUIDATA) 获得当前输入框的输入字符 tempData=get(hObject,39。 String39。 )。 将字符转换为双精度数 =str2double(tempData)*10^10。 此前指令更改了
教学难点: 正确熟练地进行计算,并能够运用所学的知识解决生活中的实际问题。 教学过程: 一、基本练习 听算 (全 班齐练,集体订正) 14- 8 12- 5 13- 6 13- 8 14- 9 12- 4 16- 9 14- 8 11- 8 15- 8 评讲: 1)说一说 12- 4 等于几你是怎样想的。 2)还有不同的想法吗。 (学生回答,教师板书) 3)在这些算法中,你最喜欢哪一种。
上好佳 (田园薯片 ) 写实型 字母 薯片图案 盼盼(艾比利) 写实型 文字 薯片图案与 人物形象 好丽友(署愿) 写实型 抽象图案加文字 薯片图案 好丽友 (好有趣 ) 写实型 抽象图案加文字 薯片图案 可比克 写实型 抽象图案加文 字和字母 薯片图案与人 物形象 乐吧 写实型 文字 薯片图案 乐事 写实型 抽象图案加字母 薯片图案 图 2 可比克薯片
The Love Between Heathcliff and Catherine The love between the two is pure, longlasting and however violent. Heathcliff’s love for Catherine is eternal that nothing can separate him from Catherine