习题1

发布时间 : 星期五 文章习题1更新完毕开始阅读

t1.showtime(); t2.settime(12,34); t2.showtime(); t3.settime(12); t3.showtime(); t4.settime(); t4.showtime(); return 0; }

4、

#include using namespace std; class ADD { public:

int add(int xx,int yy); float add(float xx,float yy);

double add(double xx,double yy); void print(int z); void print(float z); void print(double z); private: int x1,y1,z1; float x2,y2,z2; double x3,y3,z3; };

int ADD::add(int xx,int yy) { x1=xx; y1=yy;

21

z1=x1+y1; return z1; }

float ADD::add(float xx,float yy) { x2=xx; y2=yy; z2=x2+y2; return z2; }

double ADD::add(double xx,double yy) { x3=xx; y3=yy; z3=x3+y3; return z3; }

void ADD:: print(int z) {

cout<< x1<<'\\t'<< y1<<'\\t'<< z<

void ADD:: print(float z) {

cout<< x2<<'\\t'<< y2<<'\\t'<< z<

void ADD:: print(double z) {

cout<< x3<<'\\t'<< y3<<'\\t'<< z<

22

{

int m1; float m2; double m3; ADD a1,a2,a3;

cout<<\请输入两个整型数:\ int d1,d2; cin>>d1>>d2; m1=a1.add(d1,d2);

cout<<\ y z\ a1.print(m1);

cout<<\请输入两个单精度实型数:\ float b1,b2; cin>>b1>>b2; m2=a2.add(b1,b2);

cout<<\ y z\ a2.print(m2);

cout<<\请输入两个双精度实型数:\ double c1,c2; cin>>c1>>c2; m3=a3.add(c1,c2);

cout<<\ y z\ a3.print(m3); return 0; }

5、

#include class Student {

int english,computer,total; public:

void getscore();

23

void display(); void sort(Student*); ~Student(); };

void Student::getscore() {

cout<<\输入数学成绩:\ cin>>english;

cout<<\输入语文成绩:\ cin>>computer; total=english+computer; }

void Student::display() {

cout<<\数学=\语文=\总分=\}

void main() {

Student *A[5],*tmp; int i,n=5;

for (int j=0;jgetscore();

}

for(j=0;j

tmp=A[i];A[i]=A[i+1]=tmp;

24

}

cout<

for(i=0;i

A[i]->display();

25

联系合同范文客服:xxxxx#qq.com(#替换为@)