2、設計一個學生成績管理系統。某學院有三個專業ComputerScienceStudent(計科專業學生)、NetworkEngineeringStudent(網路工程專業學生)和SoftwareEngineeringStudent(軟體工程專業學生),共計50名學生。計科專業開設有課程英語、高等數學和人工智能,網路工程專業有課程英語、高等數學和計算機網路,軟體工程專業有課程英語、高等數學和軟體工程等課程。每個學生有學號、各科成績、平均成績等資訊。(1)設計一個基類學生類Student;
(2)從學生類Student分別派生三個類ComputerScienceStudent(計科專業學生)、NetworkEngineeringStudent(網路工程專業學生)和SoftwareEngineeringStudent(軟體工程專業學生);
(3)每個派生類中有一個成員函式Input()用于產生學生的相關資訊(學號和各科成績等),可用亂數產生;
(4)每個派生類中有一個成員函式Show()用于顯示學生的相關資訊(學號、各科成績和平均成績等);
(5)在main函式中:
(a)隨機產生100名三個專業的學生(可用亂數產生:rand()%3 0-計科/1-網路/2-軟體)指標放入指標陣列中;
(b)對陣列的學生呼叫Input函式,隨機產生各學生的相關資訊;
(c)對陣列的學生呼叫Show函式,顯示學生的資訊。
#include<iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Student
{
protected:
int number; double en; double ma; double pro; double ave;
public:
Student() { number = 0; en = 0; ma = 0; pro = 0; ave = 0; }
Student(int num) { number = num; en = 0; ma = 0; pro = 0; ave = 0; }
};
class ComputerScienceStudent :public Student
{
public:
ComputerScienceStudent() { number = 0; en = 0; ma = 0; pro = 0; ave = 0; }
ComputerScienceStudent(int num) :Student(num)
{
number = num; en = 0; ma = 0; pro = 0; ave = 0;
}
void Input()
{
srand((int)time(0));
en = rand() % 41 + 60;
ma = rand() % 41 + 60;
pro = rand() % 41 + 60;
ave = (en + ma + pro) / 3;
}
void Show()
{
cout << number << " " << en << " " << ma << " " << pro << " " << ave << endl;
}
};
class NetworkEngineeringStudent :public Student
{
public:
NetworkEngineeringStudent(int num) :Student(num)
{
number = num; en = 0; ma = 0; pro = 0; ave = 0;
}
void Input()
{
srand((int)time(0));
number = rand() % 50 + 51;
en = rand() % 41 + 60;
ma = rand() % 41 + 60;
pro = rand() % 41 + 60;
ave = (en + ma + pro) / 3;
}
void Show()
{
cout << number << " " << en << " " << ma << " " << pro << " " << ave << endl;
}
};
class SoftwareEngineeringStudent :public Student
{
public:
SoftwareEngineeringStudent()
{ number = 0; en = 0; ma = 0; pro = 0; ave = 0; }
SoftwareEngineeringStudent(int num) :Student(num)
{
number = num; en = 0; ma = 0; pro = 0; ave = 0;
}
void Input()
{
srand((int)time(0));
en = rand() % 41 + 60;
ma = rand() % 41 + 60;
pro = rand() % 41 + 60;
ave = (en + ma + pro) / 3;
}
void Show()
{
cout << number << " " << en << " " << ma << " " << pro << " " << ave << endl;
}
};
int main()
{
int Cnum = 0; int Nnum = 0; int Snum = 0;
int d[100]; int j;
srand((int)time(0));
for (int i = 0; i < 100; i++)
{
j = rand() % 3;
d[i] = j;
if (d[i] == 0) { Cnum++; }
if (d[i] == 1) { Nnum++; }
if (d[i] == 2) { Snum++; }
}
cout << " 計科專業:" << endl;
cout << "學號" << " " << "課程英語" << " "<< "高等數學" << " " << "人工智能" << " " << "平均分" << endl;
ComputerScienceStudent* a;
a = new ComputerScienceStudent(Snum);
srand((int)time(0));
for (int i = 0; i < Snum; i++)
{
ComputerScienceStudent s(i+1);
a[i] = s;
a[i].Input();
a[i].Show();
}
cout << " 網路工程專業:" << endl;
cout << "學號" << " " << "課程英語" << " " << "高等數學" << " " << "計算機網路" << " " << "平均分" << endl;
NetworkEngineeringStudent* b;
b =new NetworkEngineeringStudent(Nnum);
srand((int)time(0));
for (int i = 0; i < Snum; i++)
{
NetworkEngineeringStudent n(i+1);
b[i] = n;
b[i].Input();
b[i].Show();
}
cout << " 軟體工程專業:" << endl;
cout << "學號" << " " << "課程英語" << " " << "高等數學" << " " << "軟體工程" << " " << "平均分" << endl;
SoftwareEngineeringStudent* c;
c = new SoftwareEngineeringStudent(Snum);
srand((int)time(0));
for (int i = 0; i < Snum; i++)
{
SoftwareEngineeringStudent s(i + 1);
c[i] = s;
c[i].Input();
c[i].Show();
}
}
哪位大佬幫我除錯下,看看哪里出錯了?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/86022.html
標籤:C++ 語言
上一篇:學生資訊管理系統,fread和fwite有問題,求人看看
下一篇:新人問一下,望解答,謝謝
