C++ programming
Create a structure called Exam that includes exam ID (string), name of the subject (string),
registration fee (double) and the number of students registered during a week (7 days) (int
array). • Write a function called getExamDetails() which is the data type of Exam that reads the
details of the Exam and store them in the variable of the Exam structure.
Hint: Use the given function prototype as
Exam getExamDetails (Exam e);
• Write a function called calExamFee() which takes three parameters, registration fee for
the exam, the number of students registered during a week (7 days) array and the size of the array. Find the total exam registration fee during the week and print the total exam
registration to the screen. • Call the getExamDetails() and calExamFee() in the main function to print the following
output as required.
#include <iostream>
using namespace std;
struct Exam {
string examId;
string subject;
double fee;
int registeredStudents[7];
};
Exam getExamDetails(Exam e) {
cout << "Enter exam id: ";
cin >> e.examId;
cout << "Enter name of the subject: ";
cin >> e.subject;
cout << "Enter registration fee: ";
cin >> e.fee;
cout << "Enter a number of registered students during a week: \n";
for (int i = 0; i < 7; i++) {
cout << i + 1 << " - day: ";
cin >> e.registeredStudents[i];
}
return e;
}
void calExamFee(double fee, int registeredStudents[], int length) {
float Sum = 0;
for (int i = 0; i < length; i++) {
Sum += fee * registeredStudents[i];
}
cout << "Total exam fee: " << Sum << endl;
}
int main() {
Exam e, temp;
temp = getExamDetails(e);
e = temp;
calExamFee(e.fee, e.registeredStudents, 7);
return 0;
}
Comments
Leave a comment