Enter the number of students: 2
Enter the number of exams: 2
1. student's name: michael
1. student's school number: 5000
1. student's 1. exam grade: 50
1. student's 2. exam grade: 40
The avarege of this student is: 45
2. student's name: mary
2. student's school number: 6000
2. student's 1. exam grade: 70
2. student's 2. exam grade: 80
The avarege of this student is: 75
Note: bold ones are keyboard input.
The problem is i have to do that with 'new' and 'delete' operators. Here is some codes that i have tried:
void getdata()
{
int i,j;
i=0;j=0;
int number;
char *ArrStdName;
int *ArrStdSchlNum;
int examNumber;
int *ArrExam;
cout<<"Enter the number of students: "<<endl;
cin>>number;
ArrStdName = newchar[number];
ArrStdSchlNum = new (nothrow) int [number];
cout<<"Enter the number of exams: "<<endl;
cin>>examNumber;
ArrExam=new (nothrow) int [examNumber];
for (i=0;i<sayi;i++)
{
cout<<i+1<<". student's name: "<<endl;
cin>>ArrStdName[i];
cout<<i+1<<". student's school number: "<<endl;
cin>>ArrStdSchlNum[i];
for (j=0;j<tsayi;j++)
{
cout<<i+1<<". student's "<<j+1<<". exam grade: "<<endl;
cin>>ArrExam[j];
}
calculateavarege(); //this is not important right now
}
}
When I watch the variables in debug mode, all of them seem silly:\
// 10/11/2011
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int numberOFstudents;
cout << "Enter the number of students: ";
cin >> numberOFstudents;
cin.ignore(99,'\n');
int numberOFexams;
cout << "Enter the number of exams: ";
cin >> numberOFexams;
cin.ignore(99,'\n');
string student1name;
cout << "1. student's name: ";
cin >> student1name;
cin.ignore(99,'\n');
int student1SchoolNumber;
cout << "1. student's school number: ";
cin >> student1SchoolNumber;
cin.ignore(99,'\n');
int student1Examgrade1;
cout << "1. student's 1. exam grade: ";
cin >> student1Examgrade1;
cin.ignore(99,'\n');
int student1Examgrade2;
cout << "1. student's 2. exam grade: ";
cin >> student1Examgrade2;
cin.ignore(99,'\n');
int testaverage = (student1Examgrade1 + student1Examgrade2) / numberOFexams;
//// This is the output
cout <<endl << endl << "Enter the number of students: " << numberOFstudents << endl;
cout << "Enter the number of exams: " << numberOFexams << endl;
cout << "1. student's name: " << student1name << endl;
cout << "1. student's school number: " << student1SchoolNumber << endl;
cout << "1. student's 1. exam grade: " << student1Examgrade1 << endl;
cout << "1. student's 2. exam grade: " << student1Examgrade2 << endl;
cout << "The avarege of this student is: " << testaverage << endl;
cin.ignore(99,'\n');
return 1;
}
Tested your input, Output looks like this:
Enter the number of students: 2
Enter the number of exams: 2
1. student's name: michael
1. student's school number: 5000
1. student's 1. exam grade: 50
1. student's 2. exam grade: 40
The average of this student is: 45