第7章 9-10题
来源:互联网 发布:smtp 端口 编辑:程序博客网 时间:2024/06/09 18:56
第10题#include<iostream>
using namespace std;
const int maxLen = 30;
struct student
{
char fullName[maxLen];
char hobby[maxLen];
int oopLevel;
};
int getInfo(student* pa , int lenght);
void display_1(student someone);
void display_2(const student* someone);
void display_3(const student* allStudent , int nu);
int main()
{
int sizeOfClass = 0;
cout<<"请输入学生人数:";
cin>>sizeOfClass;
student* myClass = new student[sizeOfClass];
int nus = getInfo(myClass,sizeOfClass);
for(int i = 0 ; i < nus ; ++i)
{
cout<<"第"<<i+1<<"个学生信息."<<endl;
display_1(*(myClass+i));
display_2(myClass+i);
}
display_3(myClass,nus);delete [] myClass;
return 0;
}
int getInfo(student* pa , int lenght)
{
int realSize = 0;
char goEnd = 'q';
cout<<"学生信息录入,输入 'q' 退出输入.\n";
for(int i = 0 ; i < lenght ; ++i)
{
cin.get();
cout<<"请输入第"<<i+1<<"个学生的姓名";
cin.getline((pa+i)->fullName,maxLen);
if(*((pa+i)->fullName) == goEnd) //是否结束输入
break;
cout<<"请输入第"<<i+1<<"个学生的爱好.";
cin.getline((pa+i)->hobby,maxLen);
if(*((pa+i)->hobby) == goEnd)
break;
cout<<"请输入第"<<i+1<<"个学生的成绩.";
if(!(cin >> ((pa+i)->oopLevel)))
break; //输入不为整数也被认为结束输入
if((pa+i)->oopLevel < 0)
break; //输入的成绩小于0,结束输入
++realSize;
}
return realSize;
}
void display_1(student someone)
{
cout<<"姓名:"<<someone.fullName<<endl;
cout<<"爱好:"<<someone.hobby<<endl;
cout<<"成绩:"<<someone.oopLevel<<endl;
}
void display_2(const student* someone)
{
cout<<"姓名:"<<someone->fullName<<endl;
cout<<"爱好:"<<someone->hobby<<endl;
cout<<"成绩:"<<someone->oopLevel<<endl;
}
void display_3(const student* allStudent , int nu)
{
for(int i = 0 ; i < nu ; ++i)
{
cout<<"第"<<i+1<<"名学生信息."<<endl;
cout<<"姓名:"<<(allStudent+i)->fullName<<endl;
cout<<"爱好:"<<(allStudent+i)->hobby<<endl;
cout<<"成绩:"<<(allStudent+i)->oopLevel<<endl;
}
}
#include<iostream>
double add(double x , double y); //求和
double qtc(double x, double y); //求乘积
double calculate(double x , double y , double (*pt)(double , double ));
int main()
{
using namespace std;
double X = 0;
double Y = 0;
cout<<"请输入2个数字";
while(cin>>X and cin>>Y)
{
cout<<"两数之和为"<<calculate(X,Y,add)<<endl;
cout<<"两数乘积为"<<calculate(X,Y,qtc)<<endl;
cout<<"请输入2个数字";
}
cout<<"Bye!";
return 0;
}
double add(double x , double y)
{
return x+y;
}
double qtc(double x , double y)
{
return x*y;
}
double calculate(double x , double y , double (*pt)(double , double ))
{
return (*pt)(x,y);
}
- 第10章第7题
- 第7章 9-10题
- 《C Primer Plus(第5版)中文版》第7章编程练习第9题
- 《C Primer Plus(第5版)中文版》第7章编程练习第10题
- 第1章 第9题
- 第3章 第9题
- 第5章 第9题
- 第5章第9题
- 第1章 第7题
- 第3章 第7题
- 第4章 第7题
- 第7章 第1题
- 第7章第1题
- 第7章第2题
- 第7章第3题
- 第7章第4题
- 第7章 第2题
- 第7章 第3题
- C++PrimerPlus中文版(第六版)编程题答案
- 第七章1-3题
- 第7章4-6题
- 第7章 7-8题
- Python自然语言处理-第二章总结:获得文本语料与词汇
- 第7章 9-10题
- 第8章 1-3题
- 图书管理系统
- 第八章4-7题
- 第九章第1题
- linux安装mysql
- 第九章2-3题
- 第九章第4题
- 巴什博弈(hdu 2897)