Write program that models a college course. Put the declarations for StudentID,
ID: 674966 • Letter: W
Question
Write program that models a college course. Put the declarations for StudentID, Classification, Student, and Course in a header file (e.g. course.h) and the implementation for printRoll in a implemenation file
Declare a user-defined type called StudentID that uses an int as its data representation.
Declare an enumerated type called Classfication with values for FRESHMAN, SOPHOMORE, JUNIOR, SENIOR, SUPER_SENIOR, GRADUATE
Declare a struct type Student with fields for id:StudentID, name:string, year:Classification, and gpa:float
Declare a class Course with fields:
courseName:string,
size:int
MAX_SIZE: const int,
roll:Students[MAX_SIZE] and a method that prints to cout the id, name and classification of each student one per line
printRoll(): void
Write an implementation of the Course::printRoll() member function
Explanation / Answer
#include "COURSE.h"
#include <iostream>
#include <string>
using namespace std;
course::course(int num)
{
size = num;
}
void course::readData()
{
for(int i =0;i<size;i++)
{
cout<<"Enter Student ID: ";
cin>>roll[i].studentID;
cout<<"Enter Student name: ";
cin>>roll[i].name;
cout<<"Enter Student year: ";
cin>>roll[i].year;
cout<<"Enter Student gpa: ";
cin>>roll[i].gpa;
}
}
void course::printRoll()
{
cout<<"STUDENT DETAILS";
for(int i =0;i<size;i++)
{
cout<<roll[i].studentID<<roll[i].name<<roll[i].year<<roll[i].gpa;
}
}
int main()
{
int num;
cout<<"Enter how many students";
cin>>num;
course c(2);
c.readData();
c.printRoll();
return 0;
system ("pause");
}
#ifndef COURSE_H
#define COURSE_H
#include<iostream>
#include<string>
int studentID;
enum classfication {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR, SUPER_SENIOR, GRADUATE};
struct student
{
int studentID;
string name;
classfication year;
float gpa;
};
class course
{
string courseName;
int size;
const int MAX_SIZE=2;
struct student roll[MAX_SIZE];
course(int num);
public:
void readData();
void printRoll();
};
#endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.