太原理工大学_C++面向对象程序设计_实验报告

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

本科实验报告

课程名称:C++面向对象程序设计实验地点:

专业班级:

学号:

学生姓名:

指导教师:

2016年 5 月3 日

Complex::Complex(Complex &c)

{ real = c.real;

image = c.image; }

int main()

{ Complex c1;

Complex c2(0, 0);

Complex c3(c1);

cout <<"c1=";

c1.Display();

cout <<"c2=";

c2.Display();

cout <<"c3=";

c3.Display();

return 0; }

二.#include"stdafx.h"

#include

using namespace std;

class score

{

int No,Math,Phi,Data,ave;

char Name[8];

public:

void Write(score &b)

{ cout<<"请输入学号:"<

cin>>b.No;

cout<<"请输入姓名:"<

cin>>;

cout<<"请输入数学成绩:"<

cin>>b.Math;

cout<<"请输入物理成绩:"<

cin>>b.Phi;

cout<<"请输入数据结构成绩:"<

cin>>b.Data; }

int Average(score &a)

{ a.ave=(a.Data+a.Math+a.Phi)/3;

return a.ave; }

void Display()

{ cout<

};

int main ()

{ score s[3];

int i;

for(i=0;i<3;i++)

{ s[i].Write(s[i]);

s[i].Average(s[i]); }

cout<<"学号\t"<<"姓名\t"<<"数学\t"<<"物理\t"<<"结构\t"<<"平均\t"<

for(i=0;i<3;i++)

s[i].Display();

}

三. #include"stdafx.h"

#include"iostream"

using namespace std;

class Rectangle

{

public:

Rectangle(double l, double t, double r, double b) :left(l), top(t), right(r), bottom(b) {} double Diagonal();

void Show();

protected:

}

~Person() { cout <<"deconstrutor of person"<< strName << endl; }

};

class Employee :public Person {

char strDept[20];

Person Wang;

public:

Employee(char*name, int age, char*dept, char*name1, int age1) :Person(name, age), Wang(name1, age1)

{ strcpy_s(strDept, dept);

cout <<"constructor of Employee"<< endl; }

~Employee() { cout <<"deconstrucor of Employee"<< endl; }

};

int_tmain(int argc, _TCHAR* argv[])

{ Employee employee1("lixi", 20, "student", "actor", 21);

return 0;}

二.#include "stdafx.h"

#include "iostream"

using namespace std;

class Archives{

private:

int No;

char Name[8];

char Sex;

int Age;

public:

void Show(int No,char Name[8],char Sex,int Age)

{cout<<"职工号为"<

cout<<"职工姓名为"<

cout<<"职工性别为"<

cout<<"职工年龄为"<

};

class Laborage:public Archives

{

相关文档
最新文档