C++ Composition and classes with lists Programming Help!! Write a program that h
ID: 3586199 • Letter: C
Question
C++ Composition and classes with lists Programming Help!!
Write a program that has several instances of Student class (ID, First Name, Last Name, Degree, City). Each student will hold a list of courses (8 courses) that he/she has taken along with a grade for each course (A,B,C,D).
The program will ask the user to associate several courses to an existing student along with the grade obtained (i.e Sandra took MA 115 and got a B in the course).
The program should at the end print a report showing each student with all of the courses he/she has taken with all respective grades.
Explanation / Answer
It is a three file CPP program
Enter student id's in a form of array with index starting 0. Be careful of your student id while entering.
Take your time to understand the code. It is tested properly.
You can modify as your requirement.
Following are three files. Save those in *.cpp or *.h files with appropriate name
/***************************************/
/*
* UniversityProgram.cpp
*
* Created on: 04-Oct-2017
* Author:
*/
#include <iostream>
#include "Student.h"
using namespace std;
int main()
{
int N;
int st_id;
string first_name;
string last_name;
string degree;
string city;
cout<<"Enter no of student you want to record ";
cin>>N;
Student **st=new Student*[N];
for(int i=0;i<N;i++)
{
cout<<"Enter student's Id, First name, Last name, Degree, City"<<endl;
cin>>st_id>>first_name>>last_name>>degree>>city;
st[i]=new Student(st_id,first_name,last_name,degree,city);
}
string course;
char grade;
char choice;
while(choice!='n')
{
cout<<"Insert Student id,course, grade ";
cin>>st_id>>course>>grade;
st[st_id]->AddCourse(course,grade);
cout<<"Want to add another? y/n ";
cin>>choice;
}
cout<<"Enter student id to show the report";
cin>>st_id;
st[st_id]->ShowReport();
return 0;
}
/**********************************/
/*
* Student.h
*
* Created on: 04-Oct-2017
* Author:
*/
#include <string>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
#ifndef STUDENT_H_
#define STUDENT_H_
class Student {
int st_id;
string first_name;
string last_name;
string degree;
string city;
typedef pair<string,char> course;
vector<course> v;
public:
Student(int id,string first,string last,string degree,string city);
void AddCourse(string c,char grade);
void ShowReport();
};
#endif /* STUDENT_H_ */
/**************************************/
/*
* Student.cpp
*
* Created on: 04-Oct-2017
* Author:
*/
#include <iostream>
#include "Student.h"
using namespace std;
Student::Student(int id,string first,string last,string deg,string cit) {
st_id=id;
first_name=first;
last_name=last;
degree=deg;
city=cit;
// TODO Auto-generated constructor stub
}
void Student::AddCourse(string c,char grade){
v.push_back(make_pair(c,grade));
}
void Student::ShowReport(){
cout<<"Student id: "<<st_id<<" Student Name: "<<first_name<<" "<<last_name<<" Degree"<<degree<<endl;
vector<course>::iterator it;
for(it=v.begin();it!=v.end();it++)
{
cout<<"Course: "<<it->first<<" Grade: "<<it->second<<endl;;
}
}
/************************/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.