
Patrick B. answered 04/29/21
Math and computer tutor/teacher
//********* Student.h ******************//
#ifndef STUDENT_H
#define STUDENT_H
using namespace std;
#include <string>
typedef
class Student
{
public:
Student(string first, string last, double gpa);
double GetGPA() { return(gpa); }
string GetFirst() { return(first); }
string GetLast() { return(last); }
void SetGPA(double GPA) { this->gpa = GPA; }
private:
string first;
string last;
double gpa;
} * TStudent;
#define STUDENT_SIZE (sizeof(Student))
#endif
//************ Student.cpp *************************8
#ifndef STUDENT_H
#include "Student.h"
#endif
Student::Student(string firstName, string lastName, double GPA)
{
this->first = firstName;
this->last = lastName;
this->gpa = GPA;
}
//************* Course.h *********************
#ifndef COURSE_H
#define COURSE_H
#ifndef STUDENT_H
#include "Student.h"
#endif
using namespace std;
#include <vector>
typedef
class Course
{
private:
vector<Student> roster;
public:
int CountProbation();
void AddStudent(Student s) { roster.push_back(s); }
int GetNumStudents() { return(roster.size()); }
int IndexerGetStudentAtIndex(int iIndexPos, TStudent studentRec);
int LinearSearchFindStudent(string lastName, string firstName);
void ShowStudents( string strMsg);
} * TCourse;
#define COURSE_SIZE (sizeof(Course))
#endif
//********************** Course.cpp ********************
using namespace std;
#include <iostream>
#include <vector>
#ifndef COURSE_H
#include "course.h"
#endif
int Course::CountProbation()
{
int iHitCount=0;
int N = roster.size();
for (int iLoop=0; iLoop<N; iLoop++)
{
Student curStudent = (Student)roster[iLoop];
if (curStudent.GetGPA()<2.0000)
{
iHitCount++;
}
}
return(iHitCount);
}
int Course::IndexerGetStudentAtIndex(int iIndexPos, TStudent studentRec)
{
int iReturn=0;
int n = roster.size();
if (iIndexPos>=0 && iIndexPos<n)
{
*studentRec = (Student) roster[iIndexPos];
}
else
{
iReturn=-1;
}
return(iReturn);
}
int Course::LinearSearchFindStudent(string lastName, string firstName)
{
int n=roster.size();
int iIndexPos=-1;
for (int iLoop=0; iLoop<n; iLoop++)
{
Student curStudent = (Student) roster[iLoop];
if (
(lastName.compare(curStudent.GetLast())==0) && (firstName.compare(curStudent.GetFirst())==0)
)
{
iIndexPos=iLoop;
break;
}
}
return(iIndexPos);
}
void Course::ShowStudents( string strMsg)
{
int n=roster.size();
cout << "first last GPA " << endl;
for (int iLoop=0; iLoop<n; iLoop++)
{
Student curStudent = (Student)roster[iLoop];
cout << curStudent.GetFirst() << " " << curStudent.GetLast() << " " << curStudent.GetGPA() << endl;
}
}
//********************************************************
using namespace std;
#include <iostream>
#ifndef STUDENT_H
#include "student.h"
#endif
#ifndef COURSE_H
#include "course.h"
#endif
Go()
{
int yesNo=1;
string firstName;
string lastName;
double GPA;
Course course;
while (yesNo==1)
{
cout << "Please input student first name :>";
cin >> firstName;
cout << "Please input student last name :>";
cin >> lastName;
cout << "please input student GPA :>";
cin >> GPA;
Student curStudent(firstName,lastName,GPA);
course.AddStudent(curStudent);
yesNo=-1;
while (yesNo!=0 && yesNo!=1)
{
cout << "Add another student ???? 1=YES 0=NO :>";
cin >> yesNo;
}
}
string strMsg="CLASS ROSTER";
course.ShowStudents(strMsg);
cout << "-----------------------------"<<endl;
cout << " # of student on academic probation :" << course.CountProbation();
}
int main(int argc, char* argv[])
{
Go();
return 0;
}