Project 6 Objective: The purpose of this lab project is to expose you to classes
ID: 3717144 • Letter: P
Question
Project 6
Objective:
The purpose of this lab project is to expose you to classes, aggregation, and to expand your skills to write projects using classes.
Problem Specification:
Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses he/she is taking, then for each course the following data is needed
the course number a string e.g. BU 101
course credits “an integer”
grade received for the course “a character”.
The program should display each student’s information and their courses information. It should also display the GPA for the semester. The scale for each grade would be
A 4 points
B 3 points
C 2 points
D 1 points
F 0 points
Print out the complete information including the GPA. You may read the data from a file and send your output to a file.
Note that the students are not taking the same number of courses; also note that the number of credits may vary for each of the courses.
Requirements:
Define a class for course information, private data members are course number, number of credits, and the grade earned for the course.
Define another class for the student, private data members are the student name, ID number, number of courses, GPA, and a vector of course information defined above.
you may write one or multiple mutator functions to read the data for each class
Each class is defined in a header file and implemented in another.
Your client file, defines an array of student objects. To test your program, make the array sizee 2 or 3 student objects, with various number of courses, credits per course and grades.
Output the report as specified above and shown below.
Comment thoroughly and use specifications for every function.
Sample output:
&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~
CIS 161 Students GPA report
Spring 2018 Semester
&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~&~
ID# # of courses Course Grade Credits GPA
1234 4 1 A 3
2 B 4
3 C 3
4 D 2 2.66
2345 3 1 C 2
:
:
Explanation / Answer
#include "stdafx.h"
#include <string>
#include <iostream>
#include <vector>
#include "stdlib.h"
#define MAX 10 // for string nama...
using namespace std;
class course
{
public:
string course_no[10];
string credit[10];
string grade[10];
};
class student
{
private:
string student_name;
int id;
int no_Course;
float gpa;
vector <course> cour;
public:
//member function to get student's details
void getDetails(void);
};
void student::getDetails(void){
cout << "Enter student Id: " ;
cin >> id;
cout << "Enter student name: ";
cin >> student_name;
cout << "Enter Number of course: ";
cin >> no_Course;
int b; //newly added line,'b' choose to add it here because, if not, error will be occured : 'b' for gpa[b] will become undefined...
for(int b = 0; b< no_Course; b++) //loop for the courses
{
course CO;
cin.ignore();
cout << " ENTER COURSE NO : "; //Enter subject code
getline(cin,CO.course_no[b]);
cout << " ENTER CREDIT : "; //Enter subject name
getline(cin,CO.credit[b]);
cout << " ENTER GRADE : "; //Enter grade gained by student for every subject
getline(cin,CO.grade[b]);
}
}
void student::putDetails(void){
int b; //newly added line,'b' choose to add it here because, if not, error will be occured : 'b' for gpa[b] will become undefined...
int credit_hours[10];
int sem,total_subject; //'b', 'a',total_credit_hours and total_point
//are removed
float value[10],gpa;
float cgpa;
float total_point_sem = 0; //Initialise value
int total_credit_hours_sem = 0,get_point[10];
int total_credit_hours = 0; //newly added
float total_point = 0;
cout << " =================================================== ";
cout <<" student Id : " << id << endl; //display name of student
cout <<"student name : "<< student_name << endl;
for(int a = 0; a< sem ; a++) //Declaration of 'a' as int in for()
{
course CO;
cout <<" COURSE NO " << " GRADE " << " CREDIT " <<endl;
for(int b=0; b<no_Course; b++) //Declaration of 'b' as int in for()
{
cout << " " << CO.course_no[b] << " : " << CO.grade[b]<< " : " << CO.credit[b] << endl;
if(CO.grade[b]=="A")
value[b]=4;
else if(CO.grade[b]=="B")
value[b]=3;
else if(CO.grade[b]=="C")
value[b]=2;
else if(CO.grade[b]=="D")
value[b]=1;
else if(CO.grade[b]=="F")
value[b]=0;
else
value[b]=0;
get_point[b] = stoi(CO.credit[b],0) * value[b]; //multiply of credit hours and grade get for each subject
total_credit_hours += stoi(CO.credit[b]); //total cerdit hours for a sem
total_point += get_point[b]; //total points(multiple of credits hours and grade)get for a sem
}
gpa = total_point / total_credit_hours;
total_point_sem += total_point; //Total points(multiple of grade and credit hours) get for all semester
total_credit_hours_sem += total_credit_hours; //credits hour get for all semester
cgpa = total_point_sem / total_credit_hours_sem;
cout << " GPA" <<a+1<< " : " <<gpa << endl;
}
cout << " =================================================== ";
}
//member function definition, outside of the class
int main()
{
student std[MAX]; //array of objects creation
int n,loop;
cout << " ================ ";
cout << " STUDENT'S RECORD " << endl;
cout << " ================ " << endl;
cout << "Enter total number of students: ";
cin >> n;
for(loop=0;loop< n; loop++){
cout << "Enter details of student " << loop+1 << ": ";
std[loop].getDetails();
}
for(loop=0;loop< n; loop++){
cout << "Details of student " << (loop+1) << ": ";
std[loop].putDetails();
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.