当前位置: 代码迷 >> 综合 >> NEFU C++课程实验三(锐格)
  详细解决方案

NEFU C++课程实验三(锐格)

热度:58   发布时间:2023-12-01 00:44:47.0

前言:仅供大家参考,有错误大家可以指出。

5350、

#include<iostream>
#include<string.h>
using namespace std;
class Hotel{int num;string name;static int total;
public :Hotel(int num,string name){this->num=num;this->name=name;total++;}string get(){return this->name;}void show(){cout<<"input guest name query: "<<endl;cout<<" name= "<<this->name<<" "<<"no= "<<this->num<<" "<<"total= "<<this->total<<endl;}
};
int  Hotel :: total=0;
int main(){Hotel h1(1,"xdl");Hotel h2(2,"dbz");Hotel h3(3,"dcc");string name;cin>>name;if(strcmp(name.c_str(),h1.get().c_str())==0){h1.show();}if(strcmp(name.c_str(),h2.get().c_str())==0){h2.show();}if(strcmp(name.c_str(),h3.get().c_str())==0){h3.show();}
}

 5351、

#include<iostream>
using namespace std;
// // 编写程序,统计歌手大奖赛的参赛人数,每名选手的平均得分。
// 要求依次输入选手的编号、姓名、各评委的打分
// // ;输入参赛总人数,并按平均得分由高到低的顺序输出每位选手的
// 名次、姓名、平均得分
class player{int num;string name;int grade1,grade2,grade3;
public:void set(int num,string name,int grade1,int grade2,int grade3){this->num=num;this->name=name;this->grade1=grade1;this->grade2=grade2;this->grade3=grade3;}player(){}int average(){return (grade1+grade2+grade3)/3;}void show(){cout<<num<<" "<<name<<" "<<(grade1+grade2+grade3)/3<<endl;}};
int main(){int n;cin>>n;player play[n],play1[n];player p;for(int i=0;i<n;i++){int num;string name;int grade1,grade2,grade3;cin>>num;cin>>name;cin>>grade1>>grade2>>grade3;play[i].set(num,name,grade1,grade2,grade3);// play1[i].set(num,name,grade1,grade2,grade3);}for(int i=0;i<n-1;i++){for(int j=0;j<n-1;j++){if(play[j].average()<play[j+1].average()){p=play[j];play[j]=play[j+1];play[j+1]=p;}}}for(int i=0;i<n;i++){play[i].show();}
}

5358、

#include<iostream>
using namespace std;
class number{double  x,y;
public:friend void square(number &n){cin>>n.x>>n.y;cout<<n.x*n.x-n.y*n.y<<endl;}
};
int main(){number n1;square(n1);
}

 5359、

#include<iostream>
using namespace std;
class student{string name;int sorce;
public:friend void search(student s[]){student s1;for(int i=0;i<9;i++){for(int j=0;j<9;j++){if(s[j].sorce<s[j+1].sorce){s1=s[j];s[j]=s[j+1];s[j+1]=s1;}}}cout<<"max="<<s[0].name<<" "<<"min="<<s[9].name<<endl;}void set(int sorce,string name){this->sorce=sorce;this->name=name;}
};
int main(){student s[10];for(int i=0;i<10;i++){string name;cin>>name;int x;cin>>x;s[i].set(x,name);}search(s);
}

 5360、

做出来的有点问题等我再想想再发

5361、

#include<iostream>
#include<math.h>
using namespace std;
class point{int x,y;
public:friend void distance(point p1,point p2){cout<<fabs(p1.x-p2.x)<<" ";cout<<fabs(p1.y-p2.y);}point(int x,int y){this->x=x;this->y=y;}
};
int main(){ int x1,y1,x2,y2;cin>>x1>>y1;cin>>x2>>y2;point p1(x1,y1);point p2(x2,y2);distance(p1,p2);
}