|
|
我是一名学院生,
这个是我的 2nd assignment
弄了好久 都做不出,
C++ 入门 就会 ,
但现在 需要的超出了我的 知识 (都怪平时不读书)
希望大家能 帮忙解释
这个是 题目
Q1 )
a) creat a two dimensional arry to store the marks of all students in a class as shown in the table below :
| | AEMS 1043 | DMAP 1214 |
| 1st student | 80 | 70 |
| 2nd student | 65 | 68 |
- the marks for each unit are to be keyed in by the user and stored in the two dimensionnal array ,
- the number of student in a class is not fixed . Use # define CLASS_SIZE ... to cater for the required size .
- the program calculates the grade point averange ( GPA ) for each student .
b) two reports are to be displayed : Examination Performance Report and Result analysis report .
refer to the report formats on page3 , you will need to access the appropiate array you have created earlier , and create more arrays where necessary
( 应该 用什么 code 可以让一个 input data 出现 两个 dos out put , 还是 同一个 dos output 两个 result ?? )
问题 : 1 ) 我要怎样 弄 一个 array 里面包含 了 名字 和 course code ? 但要 key - in 分数 ,
double darr[row][column] = {0.0};
char carr[row][column] = {'\0'};
for (int i = 0; i < row ; i++)
{ for ( int j =0 ; j < column ; j ++)
cout << darr [j] << "\t";
cout << endl;}
是不是 应该 使用
arry[1][3]
cin >> name >> name
then name = arry[0]
cout >> arry[0]
加上 for , if else , while loop 来 cin 呢?
2) # define CLASS_SIZE
#include "cl_info.h"
void average(struct student class[]);
int main(void)
{
struct student temp, class[CLASS_SIZE];
temp.grade = 'A';
temp.last_name = "Bushker";
temp.student_id = 590017;
temp.grade = 'B';
temp.last_name = "Donald";
temp.student_id = 590117;
temp.grade = 'C';
temp.last_name = "Trump";
temp.student_id = 590217;
temp.grade = 'A';
temp.last_name = "Lewis";
temp.student_id = 590317;
temp.grade = 'B';
temp.last_name = "Smith";
temp.student_id = 590417;
average(class);
return 0;
}
void average(struct student class[])
{
double sum=0.0,avg;
int i;
for(i=0;i<5;++i){
if(class.grade == 'A');
sum+=4;
if(class.grade == 'B');
sum+=3;
if(class.grade == 'C');
sum+=2;
if(class.grade == 'D');
sum+=1;
if(class.grade == 'F');
sum+=0;
}
avg = (sum/5);
printf("The average for the class is %f.\n", avg);
这个是 从 google search 来的 , 这一题能用这个 方法做么?
题目 2 )
a) defien a structure variable that can store an index number ( eg.05WTD05646) , a student full name ,and the gender .
Create an array of this structure to store details of all student in the class . The details are to be keyed in by the user .
(the first student's details will be stored as the first element of the array , and so on ) |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-1-2008 11:56 PM
|
显示全部楼层
|
对了。。。。我是使用 microsoft visual C++ 的 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 2-1-2008 06:29 PM
|
显示全部楼层
没有人能回复么? 。。。
我写了出来。。。不过出现了 logic error 。。。。
哪位 大大 能帮忙 看一看?? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 2-1-2008 06:34 PM
|
显示全部楼层
#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
const int NUM_STUDENT = 2;
const int NUM_SUBJECT = 2;
const int NUM_GRADE = 10;
double data[NUM_STUDENT][NUM_SUBJECT];
double GPA[NUM_STUDENT];
double analysis[NUM_GRADE][NUM_SUBJECT];
int student, subject,numstudent1,numstudent2, numgrade, a, z;
string grade[NUM_STUDENT][NUM_SUBJECT], gender[NUM_STUDENT], Male, Female, index[NUM_STUDENT], name[NUM_STUDENT], call[NUM_STUDENT];
double GP, QP, credit, tQP = 0, tGPA = 0, AVEGPA, minGPA, maxGPA;
cout<<"Enter the marks for students"<<endl;
cout<<"Subject 1 is AACS1084, subject 2 is AACS1123"<<endl;
cout<<endl;
for(student = 0; student < NUM_STUDENT; student++)
{
cout<<" lease enter your index number:";
cin >>index[student];
cout<<" lease enter your name without spacing them:";
cin >>name[student];
cout<<" lease enter ur genter M/F)";
cin >>gender[student];
while(gender[student] != "M" && gender[student] != "F"
{
cout<<"Incorrect input"<<endl;
cout<<" lease enter ur genter M/F)";
cin >>gender[student];
}
if(gender[student] == "M"
{ gender[student] = "Male";
call[student] = "Mr.";
}
else if(gender[student] == "F"
{ gender[student] = "Female";
call[student] = "Miss.";
}
for (subject = 0; subject < NUM_SUBJECT; subject++)
{
cout<< "Student " << (student + 1);
cout<<", Subject " << (subject + 1) << ": ";
cin >> data[student][subject];
while(data[student][subject]< 0 || data[student][subject] > 100)
{
cout<<" lease enter the marks between 0 to 100"<<endl;
cin >> data[student][subject];
}
}
cout<<endl;
}
for(student = 0;student < NUM_STUDENT; student++)
{
for(subject = 0; subject < NUM_SUBJECT; subject++)
{
if (data[student][subject] < 40)
{
grade[student][subject] = "F";
GP = 0.00;
a = 9;
}
else if (data[student][subject] < 45)
{
grade[student][subject] = "D";
GP = 1.00;
a = 8;
}
else if (data[student][subject] < 50)
{
grade[student][subject] = "C-";
GP = 1.75;
a = 7;
}
else if (data[student][subject] < 55)
{
grade[student][subject] = "C";
GP = 2.00;
a = 6;
}
else if (data[student][subject] < 60)
{
grade[student][subject] = "C+";
GP = 2.50;
a = 5;
}
else if (data[student][subject] < 65)
{
grade[student][subject] = "B-";
GP = 2.75;
a = 4;
}
else if (data[student][subject] < 70)
{
grade[student][subject] = "B";
GP = 3.00;
a = 3;
}
else if (data[student][subject] < 75)
{
grade[student][subject] = "B+";
GP = 3.50;
a = 2;
}
else if (data[student][subject] < 80)
{
grade[student][subject] = "A-";
GP = 3.75;
a = 1;
}
else if (data[student][subject] <= 100)
{
grade[student][subject] = "A";
GP = 4.00;
a = 0;
}
if(subject == 0)
credit = 4;
else if(subject == 1)
credit = 3;
QP = GP * credit;
tQP += QP;
}
GPA[student] = tQP/7;
tQP = 0;
for(z = 0; z < NUM_STUDENT; z++)
{
if( z == student)
for(numgrade = 0; numgrade < NUM_GRADE; numgrade++)
if(numgrade == a)
{
analysis[z][numgrade] += 1;
}
}
}
//system("cls" ;
cout<< fixed << showpoint << setprecision(3);
cout<<"\t\t\t EXAMINATION REPORT\t\t"<<endl;
cout<<"\t\t\t __________________\t\t"<<endl;
cout<<endl;
cout<<"Student No.\t\tAACS1084\tACCS1123\tGrade Point Average"<<endl;
cout<<"___________\t\t________\t________\t___________________"<<endl;
for(student = 0; student < NUM_STUDENT; student++)
{
cout<<" "<< student+1 << "\t\t\t " <<grade[student][0]<<"\t\t "<<grade[student][1]<<"\t"<<"\t\t"<<GPA[student]<<endl;
}
for ( student=0; student < NUM_STUDENT; student++)
{
tGPA += GPA[student];
}
AVEGPA = tGPA/NUM_STUDENT;
maxGPA = GPA[0];
for(student = 1; student < NUM_STUDENT; student++)
{
if(GPA[student] > maxGPA)
maxGPA = GPA[student];
}
minGPA = GPA[0];
for(student = 1; student < NUM_STUDENT; student++)
{
if(GPA[student] < minGPA)
minGPA = GPA[student];
}
for(student = 0; student < NUM_STUDENT; student++)
{
if (GPA[student]==maxGPA)
numstudent1=(student+1);
}
for(student = 0; student < NUM_STUDENT; student++)
{
if (GPA[student]==minGPA)
numstudent2=(student+1);
}
cout<<endl<<endl<<endl;
cout<<"AVERAGE GPA " << AVEGPA <<endl;
cout<<"HIGHEST GPA " << maxGPA;
cout<<"\tobtained by Student No. " << numstudent1<<endl;
cout<<"LOWEST GPA " << minGPA;
cout<<"\tobtained by Student No. "<< numstudent2<<endl;
//system("pause" ;
//system("cls" ;
cout<<"\t\t\t RESULTS ANALYSIS\t\t\t"<<endl;
cout<<"\t\t\t ________________\t\t\t"<<endl;
cout<<" A A- B+ B B- C+ C C- D F TOTAL"<<endl;
cout<<"AACS1084 ";
for(numgrade = 0; numgrade < NUM_GRADE; numgrade++)
{
for(z = 0; z < NUM_SUBJECT; z++)
{
cout<<analysis[0][numgrade]<<" ";
}
}
cout<<endl;
cout<<"AACS1123 ";
for(numgrade = 0; numgrade < NUM_GRADE; numgrade++)
cout<<analysis[0][0]<<" ";
cout<<endl;
cout<<endl<<endl;
cout<<"Total "<<endl;
//system("pause" ;
//system("cls" ;
for(student = 0; student < NUM_STUDENT; student++)
{
cout<<"\t\t\tEXAMINATION RESULT NOTIFICATION"<<endl;
cout<<"\t\t\t_______________________________"<<endl;
cout<<endl;
cout<<"Name :"<< call[student] << name[student] <<"\t\t\t\tINDEX NO "<<index[student]<<endl;
cout<<"Gender :"<<gender[student]<<endl;
cout<<endl;
cout<<"Your examination results are as follows:"<<endl;
cout<<endl;
cout<<"UNIT CODE\tUNIT TITLE\t\t\t\t\tGRADE"<<endl;
cout<<"_________\t____ _____\t\t\t\t\t_____"<<endl;
cout<<"AACS1084\tProgramming Concepts & Design II\t\t " <<grade[student][0]<<endl;
cout<<"AACS1123\tPrinciples of Information Systems\t\t " <<grade[student][1]<<endl;
cout<<endl<<endl<<endl;
cout<<"GRADE POINT AVERAGE :\t\t\t\t\t\t"<<GPA[student]<<endl;
}
return 0;
} |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 2-1-2008 06:36 PM
|
显示全部楼层
这个比较新改良的
#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
const int NUM_STUDENT = 2;
const int NUM_SUBJECT = 2;
const int NUM_GRADE = 10;
double data[NUM_STUDENT][NUM_SUBJECT];
double GPA[NUM_STUDENT];
double analysis[NUM_GRADE][NUM_SUBJECT];
int student, subject,numstudent1,numstudent2, numgrade, a, z, A = 0, Aneg=0, Bpos=0, B=0, Bneg=0, Cpos=0, C=0, Cneg=0, D=0, F=0;
string grade[NUM_STUDENT][NUM_SUBJECT], gender[NUM_STUDENT], Male, Female, index[NUM_STUDENT], name[NUM_STUDENT], call[NUM_STUDENT];
double GP, QP, credit, tQP = 0, tGPA = 0, AVEGPA, minGPA, maxGPA;
cout<<"Enter the marks for students"<<endl;
cout<<"Subject 1 is AACS1084, subject 2 is AACS1123"<<endl;
cout<<endl;
for(student = 0; student < NUM_STUDENT; student++)
{
cout<<" lease enter your index number:";
cin >>index[student];
cout<<" lease enter your name without spacing them:";
cin >>name[student];
cout<<" lease enter ur genter M/F)";
cin >>gender[student];
while(gender[student] != "M" && gender[student] != "F"
{
cout<<"Incorrect input"<<endl;
cout<<" lease enter ur genter M/F)";
cin >>gender[student];
}
if(gender[student] == "M"
{ gender[student] = "Male";
call[student] = "Mr.";
}
else if(gender[student] == "F"
{ gender[student] = "Female";
call[student] = "Miss.";
}
for (subject = 0; subject < NUM_SUBJECT; subject++)
{
cout<< "Student " << (student + 1);
cout<<", Subject " << (subject + 1) << ": ";
cin >> data[student][subject];
while(data[student][subject]< 0 || data[student][subject] > 100)
{
cout<<" lease enter the marks between 0 to 100"<<endl;
cin >> data[student][subject];
}
}
cout<<endl;
}
for(student = 0;student < NUM_STUDENT; student++)
{
for(subject = 0; subject < NUM_SUBJECT; subject++)
{
if (data[student][subject] < 40)
{
grade[student][subject] = "F";
GP = 0.00;
F = F + 1;
}
else if (data[student][subject] < 45)
{
grade[student][subject] = "D";
GP = 1.00;
D = D + 1;
}
else if (data[student][subject] < 50)
{
grade[student][subject] = "C-";
GP = 1.75;
Cneg = Cneg + 1;
}
else if (data[student][subject] < 55)
{
grade[student][subject] = "C";
GP = 2.00;
C = C + 1;
}
else if (data[student][subject] < 60)
{
grade[student][subject] = "C+";
GP = 2.50;
Cpos = Cpos + 1;
}
else if (data[student][subject] < 65)
{
grade[student][subject] = "B-";
GP = 2.75;
Bneg = Bneg + 1;
}
else if (data[student][subject] < 70)
{
grade[student][subject] = "B";
GP = 3.00;
B = B + 1;
}
else if (data[student][subject] < 75)
{
grade[student][subject] = "B+";
GP = 3.50;
Bpos = Bpos + 1;
}
else if (data[student][subject] < 80)
{
grade[student][subject] = "A-";
GP = 3.75;
Aneg = Aneg + 1;
}
else if (data[student][subject] <= 100)
{
grade[student][subject] = "A";
GP = 4.00;
A = A + 1;
}
if(subject == 0)
credit = 4;
else if(subject == 1)
credit = 3;
QP = GP * credit;
tQP += QP;
cout<<A<<Aneg<<Bpos<<B<<Bneg<<Cpos<<C<<Cneg<<D<<F<<endl;
}
GPA[student] = tQP/7;
tQP = 0;
}
//system("cls" ;
cout<< fixed << showpoint << setprecision(3);
cout<<"\t\t\t EXAMINATION REPORT\t\t"<<endl;
cout<<"\t\t\t __________________\t\t"<<endl;
cout<<endl;
cout<<"Student No.\t\tAACS1084\tACCS1123\tGrade Point Average"<<endl;
cout<<"___________\t\t________\t________\t___________________"<<endl;
for(student = 0; student < NUM_STUDENT; student++)
{
cout<<" "<< student+1 << "\t\t\t " <<grade[student][0]<<"\t\t "<<grade[student][1]<<"\t"<<"\t\t"<<GPA[student]<<endl;
}
for ( student=0; student < NUM_STUDENT; student++)
{
tGPA += GPA[student];
}
AVEGPA = tGPA/NUM_STUDENT;
maxGPA = GPA[0];
for(student = 1; student < NUM_STUDENT; student++)
{
if(GPA[student] > maxGPA)
maxGPA = GPA[student];
}
minGPA = GPA[0];
for(student = 1; student < NUM_STUDENT; student++)
{
if(GPA[student] < minGPA)
minGPA = GPA[student];
}
for(student = 0; student < NUM_STUDENT; student++)
{
if (GPA[student]==maxGPA)
numstudent1=(student+1);
}
for(student = 0; student < NUM_STUDENT; student++)
{
if (GPA[student]==minGPA)
numstudent2=(student+1);
}
cout<<endl<<endl<<endl;
cout<<"AVERAGE GPA " << AVEGPA <<endl;
cout<<"HIGHEST GPA " << maxGPA;
cout<<"\tobtained by Student No. " << numstudent1<<endl;
cout<<"LOWEST GPA " << minGPA;
cout<<"\tobtained by Student No. "<< numstudent2<<endl;
//system("pause" ;
//system("cls" ;
cout<<"\t\t\t RESULTS ANALYSIS\t\t\t"<<endl;
cout<<"\t\t\t ________________\t\t\t"<<endl;
cout<<" A A- B+ B B- C+ C C- D F TOTAL"<<endl;
cout<<"AACS1084 ";
for(numgrade = 0; numgrade < NUM_GRADE; numgrade++)
{
for(z = 0; z < NUM_SUBJECT; z++)
{
cout<<analysis[0][numgrade]<<" ";
}
}
cout<<endl;
cout<<"AACS1123 ";
for(numgrade = 0; numgrade < NUM_GRADE; numgrade++)
cout<<analysis[0][0]<<" ";
cout<<endl;
cout<<endl<<endl;
cout<<"Total "<<endl;
//system("pause" ;
//system("cls" ;
for(student = 0; student < NUM_STUDENT; student++)
{
cout<<"\t\t\tEXAMINATION RESULT NOTIFICATION"<<endl;
cout<<"\t\t\t_______________________________"<<endl;
cout<<endl;
cout<<"Name :"<< call[student] << name[student] <<"\t\t\t\tINDEX NO "<<index[student]<<endl;
cout<<"Gender :"<<gender[student]<<endl;
cout<<endl;
cout<<"Your examination results are as follows:"<<endl;
cout<<endl;
cout<<"UNIT CODE\tUNIT TITLE\t\t\t\t\tGRADE"<<endl;
cout<<"_________\t____ _____\t\t\t\t\t_____"<<endl;
cout<<"AACS1084\tProgramming Concepts & Design II\t\t " <<grade[student][0]<<endl;
cout<<"AACS1123\tPrinciples of Information Systems\t\t " <<grade[student][1]<<endl;
cout<<endl<<endl<<endl;
cout<<"GRADE POINT AVERAGE :\t\t\t\t\t\t"<<GPA[student]<<endl;
}
return 0;
} |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 2-1-2008 06:38 PM
|
显示全部楼层
为什么 我 cout statistics 那里 会出现 乱码的?
还有那个 compare 那里
===〉
for(student = 0;student < NUM_STUDENT; student++)
{
for(subject = 0; subject < NUM_SUBJECT; subject++)
{
if (data[student][subject] < 40)
{
grade[student][subject] = "F";
GP = 0.00;
F = F + 1;
}
else if (data[student][subject] < 45)
{
grade[student][subject] = "D";
GP = 1.00;
D = D + 1;
}
else if (data[student][subject] < 50)
{
grade[student][subject] = "C-";
GP = 1.75;
Cneg = Cneg + 1;
}
else if (data[student][subject] < 55)
{
grade[student][subject] = "C";
GP = 2.00;
C = C + 1;
}
else if (data[student][subject] < 60)
{
grade[student][subject] = "C+";
GP = 2.50;
Cpos = Cpos + 1;
}
else if (data[student][subject] < 65)
{
grade[student][subject] = "B-";
GP = 2.75;
Bneg = Bneg + 1;
}
else if (data[student][subject] < 70)
{
grade[student][subject] = "B";
GP = 3.00;
B = B + 1;
}
else if (data[student][subject] < 75)
{
grade[student][subject] = "B+";
GP = 3.50;
Bpos = Bpos + 1;
}
else if (data[student][subject] < 80)
{
grade[student][subject] = "A-";
GP = 3.75;
Aneg = Aneg + 1;
}
else if (data[student][subject] <= 100)
{
grade[student][subject] = "A";
GP = 4.00;
A = A + 1;
}
if(subject == 0)
credit = 4;
else if(subject == 1)
credit = 3;
QP = GP * credit;
tQP += QP;
cout<<A<<Aneg<<Bpos<<B<<Bneg<<Cpos<<C<<Cneg<<D<<F<<endl;
}
做不出 该有的 。。。。
该怎么改良? |
|
|
|
|
|
|
|
|
|
|
发表于 15-5-2008 09:29 PM
|
显示全部楼层
好久沒有學c++了,不過,我現在learning java...  |
|
|
|
|
|
|
|
|
|
|
发表于 16-5-2008 06:27 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 17-5-2008 02:55 PM
|
显示全部楼层
|
放breakpoint,go to breakpoint 和 step in,一步一步来check,加用watch来看各个variable在什么时候是什么value。应该能debug的 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|