- 0
- 0
- 约5.17千字
- 约 5页
- 2020-06-21 发布于浙江
- 举报
C++实验程序
精品文档
精品文档
收集于网络,如有侵权请联系管理员删除
收集于网络,如有侵权请联系管理员删除
精品文档
收集于网络,如有侵权请联系管理员删除
实验2
//lab4_1.cpp
#include iostream
using namespace std;
enum CPU_Rank {P1=1,P2,P3,P4,P5,P6,P7};
class CPU
{private:
CPU_Rank rank;
int frequency;
float voltage;
public:
CPU (CPU_Rank r, int f, float v)
{ rank = r;
frequency = f;
voltage = v;
cout 构造了一个CPU! endl;
}
~CPU () { cout 析构了一个CPU! endl; }
CPU_Rank GetRank() const { return rank; }
int GetFrequency() const { return frequency; }
float GetVoltage() const { return voltage; }
void SetRank(CPU_Rank r) { rank = r; }
void SetFrequency(int f) { frequency = f; }
void SetVoltage(float v) { voltage = v; }
void Run() {cout CPU开始运行! endl; }
void Stop() {cout CPU停止运行! endl; }
};
int main()
{
CPU a(P6,300,2.8);
a.Run();
a.Stop();
}
实验4
#include iostream
#include string
using namespace std;
class Employee
{
private:
char name[30];
char street[30];
char city[18];
char zip[7];
public:
Employee(char *n, char *str, char *ct, char *z);
void change_name(char *n);
void display();
};
Employee::Employee (char *n,char *str,char *ct, char *z)
{ strcpy(name, n);
strcpy(street, str);
strcpy(city, ct);
strcpy(zip, z);
}
void Employee::change_name (char *n)
{ strcpy(name, n);
}
void Employee::display ()
{ cout name street ;
cout city zip endl;
}
// lab6_6.cpp
#include employee.h
int main()
{
Employee emp[5] =
{ Employee(张三,平安大街3号, 北京, 100000),
Employee(李四,王府井大街20号, 北京, 100000),
Employee(赵刚,中山路112号, 重庆, 400000),
Employee(陈芳,南京路234号, 上海, 200000),
Employee(周欣,人民东路476号, 重庆, 400000)};
for(int i=0;i5;i++)
emp[i].display();
}
实验5
#include iostream
using namespace std;
class vehicle
{
private:
int MaxSpeed;
int Weight;
public:
vehicle(){MaxSpeed=0; Weight=0;};
~vehicle(){};
void Run() {cout Now it is running! endl; }
void Stop() {cout Now it has stopped! endl; }
};
class bicycle : virtual public vehicle
{
private:
int Height;
public:
bicycle(){};
~bicy
原创力文档

文档评论(0)