16年真题:
宿舍管理系统/学生管理系统
简单的学生管理系统
17年真题:
1.输入一个数字,为其高,一个符号*,输出该符号组成的平行四边形形状。
#include<fstream>
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = n - i; j >= 1; j--)
cout << " ";
for (int k = 1; k <= n; k++)
cout << "*";
cout << endl;
}
return 0;
}
2.是猴子吃桃问题,每天都吃剩下的一半,再多吃一个,直到第十天剩下一个桃子,问第一天猴子有多少个桃。
#include<fstream>
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
int sum = 0, t = 1;
for (int i = 1; i < n; i++)
{
sum = (t + 1) * 2;
t = sum;
}
cout << sum << endl;
return 0;
}
3.输入一系列的数字,输出他们正负数个数,输入0截止,要用函数实现 。
#include<fstream>
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
void fun()
{
int a = 0, b = 0, n;
while (cin >> n)
{
if (n == 0)
break;
if (n > 0)a++;
else if (n < 0)b++;
}
cout << "正数个数:" << a << endl;
cout << "负数个数:" << b << endl;
}
int main()
{
fun();
return 0;
}
4.是用一个类来记录学生成绩和他班级,里面有几个函数,静态成员和动态成员都有。
#include<fstream>
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
class Student {
private:
string num;
string name;
string class_;
float score;
static int cnt;
static float sum;
static float ave;
public:
Student(string n,string na,string c,float s)
{
num = n;
name = na;
class_ = c;
score = s;
cnt++;
sum = sum + s;
}
static float average() {
ave = sum / cnt;
return ave;
}
static float getTotal()
{
return sum;
}
void getData()
{
cout << "输出 学号 姓名 班级 成绩:" << endl;
cout << "num: " << num << endl;
cout << "name: " << name << endl;
cout << "class: " << class_ << endl;
cout << "score: " << score << endl;
}
};
float Student::ave = 0;
float Student::sum = 0;
int Student::cnt = 0;
int main()
{
Student Stu[5] = {
Student("101","小明","十班",89.5),
Student("102","Mike","十班",77.5),
Student("103","Jackson","十班",87.0),
Student("104","Cherry","十班",93.5),
Student("105","Oscar","十班",89.0)
};
cout << "总分:" << Student::getTotal() << endl;
cout << "平均分:" << Student::average() << endl;
return 0;
}
5.重载+,++,=等简单运算符
时间相加减
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
class Time {
private:
int sec;
int min;
public:
//构造函数
Time(int m = 0, int s = 0)
{
min = m;
sec = s;
}
void operator=(Time a)
{
min = a.min;
sec = a.sec;
}
friend ostream & operator<<(ostream & out, Time& a)
{
out << a.min << "/" << a.sec << endl;
return out;
}
Time operator+(Time &a);
Time operator++();//前置
Time operator++(int);//后置
};
Time Time::operator+(Time &a)
{
Time c;
c.min = a.min + min;
c.sec = a.sec + sec;
if (c.sec >= 60)
{
c.sec -= 60;
c.min++;
}
return c;
}
Time Time::operator++()
{
sec++;
if (sec >= 60)
{
sec -= 60;
min++;
}
return *this;
}
Time Time::operator++(int)
{
Time t = *this;
sec++;
if (sec >= 60)
{
sec -= 60;
min++;
}
return t;
}
int main()
{
Time a;
cout << "a:";
cout << a << endl;
a++;
cout << "a++:";
cout << a << endl;