need some hand

WAP a C++ program using Structures to calculate the total and average of scores of a selected student. The program should prompt the student to input the stu_id. This stu_id is checked against the stu-ids’ and make sure it really exists. Calculate the total and average, if the scores in assignment1 (out of 10 marks), assignment2 (out of 10 marks), mid-term score (out of 30 marks), and final score (out of 50 marks) are given.
closed account (48T7M4Gy)
And the problem is??
closed account (48bpfSEw)


I'm bored, so I'll do your homework for you as a sketch! ^^

WAP a C++ program using Structures

1
2
3
4
5
class Student {
   int    iID;
   string strName;
   int    iScore;
}


to calculate the total and average of scores of a selected student.

1
2
int iTotal=0;
int iAverage=0;



The program should prompt the student to input the stu_id.

1
2
3
4
5
6
7
8
9
10
11
12
13

Student stdnt;

cout << "Please enter next student data: ";

cout << "ID: ";
cin >> stdnt.iID;

cout << "Name: ";
cin >> stdnt.strName;

cout << "Score: ";
cin >> stdnt.iScore;


This stu_id is checked against the stu-ids’ and make sure it really exists.

1
2
3
4
5
map <int, Student> mapStudent;

mapStudent[1] = Student(1, "Brad Pit", 0);
...
mapStudent[6] = Student(6, "Fox Megan", 0);     // huuu, she has the id six... ^^ 



1
2
3
4
5
6
7
8
9
10
11
12
13

// ASSERTS

map <int, Student>::iterator it = mapStudent.find (stdnt.iID);
if (it == mapStudent.end())
  throw "Student ID not found!"
  
if (it->second.strName != stdnt.strName) 
  throw "Student ID found, but Name is wrong!"
  
if (stdnt.iScore < 0 && stdnt.iScore > 10) 
  throw "Score is not in range!"  



Calculate the total and average, if the scores in assignment1 (out of 10 marks), assignment2 (out of 10 marks), mid-term score (out of 30 marks), and final score (out of 50 marks) are given.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

map<string, double>  mapValues;

mapValues["assignment1"] =0;
mapValues["assignment2"] =0;
mapValues["assignment3"] =0;
mapValues["finalScore"]  =0;

for (map <int, Student>::iterator it = mapStudent.begin();
     it != mapStudent.end(); ++it) {
     
  if (it->second.iScore > 10)
    mapValues["assignment1"] ++;
  else if (it->second.iScore > 20)
    mapValues["assignment2"] ++;
  else if (it->second.iScore > 30)
    mapValues["assignment3"] ++;
  else if (it->second.iScore > 50)
    mapValues["finalScore"] ++;
  }



Output the result

1
2
3
4
5
 
for (map <string, double>::iterator it = mapValues.begin();
     it != mapValues.end(); ++it) {
  cout << it->first << " : " << it->second;
  }


Topic archived. No new replies allowed.