Question

Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

Files given in this assignment (right-click on the file to download)

  • Assignment7.cpp (need to complete)

  • Student.h (Given. Just use it, don't change it!)

  • Student.cpp (Partially filled, need to complete)

1. Assignment description

In this assignment, you will write a simple class roster management system for ASU CSE100.

Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h, according to it, finish the Student.cpp file (class definition). Review the lecture notes on class declaration and definition if you forgot how to do it.

Student
-id: string
-name: string
-gpa: double
+Student()
+Student(string, string,double)
+getID(): string
+getName(): string
+getGPA(): double
+setID(string): void
+changeName(string): void
+changeGPA(double): void
+toString(): string

Step #2. After you complete Student.cpp, assume you're the instructor of CSE100, you have the authority to search, check or update a student's profile. You are given a skeleton of a driver's program called Assignment7.cppthat will used the above defined Student class. //---- is where you will need to fill in your own codes according to the instructions. The Assignment7.cpp contains the main() and multiple other functions inside. Below please find each function's description, you are requried to design at least these functions, feel free to add any other functions if you find it's necessary and easier for you to finish the assignment.

Function Function's Description
int getStudentData(Student anArray[MAX]) This is the function we used to read in students' data from a text file and store it inside anArray that contains MAX number of Student objects. This function returns the actual number of students we read in from the text file.

Inside the body of the function, make sure to prompt to let user enter the text file's name as follows:

cout << "Please enter the file name where I will read the data from: ";
cin >> fileName;

Hint: each line of the input file represents one student's info, it contains a student's ID, name and gpa. After read in one student's data, call Student class constructor to create one Student object, then store it inside anArray.
int getChoice() This function inputs, validates, and returns user's choice. User's choice is an integer and should range from 1 to 8. Inside this funciton you will need to implement a validation loop. See below displayMenu( ) for user choice.
void displayMenu() This function is given to you and it will display the following menu on screen:

******CSE100 Course Management System*******
1 - Search by ID
2 - Search by name
3 - Change a student name
4 - Modify a student gpa
5 - Display award list
6 - Compute average gpa
7 - Display class roster
8 - Quit
int searchByID(Student aClassroster[], int size, string id) This function corresponds to above menu option #1 - Search by ID. Given an array of Student called aClassroster and its size, we will search whether the given student id is inside the array or not, if it's inside, return its index, otherwise return -1. (Hint: this is actually a linear search on id, check our lecture notes on linear search)
int searchByName(Student aClassroster[], int size, string name) This function corresponds to above menu option #2 - Search by name. Given an array of Student called aClassroster and its size, we will search whether the given student name is inside the array or not, if it's inside, return its index, otherwise return -1.
bool changeStudentName(Student aClassroster[], int size, string oldName, string newName) This function corresponds to above menu option #3 - Change a student name. Given an array of Student called aClassroster and its size, we will search whether the given student oldName is inside the array or not, if it's inside, we will change/replace it by the corresponding newName and returns true; otherwise the function should return false. (Hint: this function should call searchByName( ) )
bool modifyStudentGPA(Student aClassroster[], int size, string id, double newGpa) This function corresponds to above menu option #4 - Modify a student gpa. Given an array of Student called aClassroster and its size, we will search whether the given student id is inside the array or not, if it's inside, we will change/update the corresponding student's gpa by the newGpa and returns true; otherwise the function should return false. (Hint: this function should call searchByID( ) )
void displayAwardList(Student aClassroster[], int size, string awardType) This function corresponds to above menu option #5 - Display award list. Given an array of Student called aClassroster and its size, also a string awardType, if awardType equals "P" (which represents the President's Award), all students' info. whose gpa >= 3.75 should be displayed on screen; if  awardType equals "D" (which represents the Dean's Award), all students' info. whose gpa >= 3.5 should be displayed on screen.
double computeAverageGPA(Student aClassroster[], int size) This function corresponds to above menu option #6 - Compute average gpa. Given an array of Student called aClassroster and its size, this function returns the average gpa of all students in aClassroster.
void displayClassRoster(Student aClassroster[], int size) This function corresponds to above menu option #7 - Display class roster. Given an array of Student called aClassroster and its size, this function display all students' info. on screen. (Check sample run for output format)

Step #3. After you finish designing above functions, next you will need to finish the main() function. The main() function uses a do..while loop and will display the following menu on screen:

******CSE100 Course Management System*******
1 - Search by ID
2 - Search by name
3 - Change a student name
4 - Modify a student gpa
5 - Display award list
6 - Compute average gpa
7 - Display class roster
8 - Quit

Then the program will ask “Pick from above menu: ”, user will type in an integer of their menu choice, the program then proceed to the relevant part accordingly. The skeleton of the program is given to you, you will need to fill in what has been left.

//************************************************
// FILE: Student.h

#ifndef STUDENT_H
#define STUDENT_H

#include 

using namespace std;

class Student
{
    private:
        string id;
        string name;
        double gpa;
    public:
        Student();                       //default constructor
        Student(string, string, double); //overloadded constructor
        string getID();             //accessor for id
        void setID(string);         //mutator for id
        string getName();           //accessor for name
        void changeName(string);    //mutator for name
        double getGPA();           //accessor for gpa
        void changeGPA(double);   //mutator for gpa
        string toString();
};

#endif
//************************************************
// FILE: Student.cpp

//include the header file
//----
#include 
#include 
#include 

//The default constructor
Student::Student()
{
    id = "?";
    name = "?";
    gpa = 0.0;
}

//The overloadded constructor
Student::Student(string newID, string newName, double newGpa)
{
   id = newID;
   name = newName;
   gpa = newGpa;
}

//accessors & mutators for instance variable 'id'
string Student::getID()
{
    return id;
}

void Student::setID(string newID)
{
        id = newID;
}

//***************************************************************
//Check the header file and finish the remaining functions below
 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// StudentsInfo.txt

111 Sachin 3.6
222 Simkox 3.8
333 Pointing 4.0
444 Rahul 3.2
555 James 3.0

____________________

// Student.h

#ifndef STUDENT_H
#define STUDENT_H
#include <string>
class Student
{
public:
Student();
Student(string ,string ,double);
string getID();
string getName();
void changeName(string);
double getGPA();
void changeGPA(double);
string toString();
  
private:
// Declaring variables
string id;
string name;
double gpa;

};
#endif


___________________________

// Student.cpp

#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
using namespace std;
#include "Student.h"

Student::Student()
{
id="?";
name="?";
gpa=0.0;
}
Student::Student(string id,string name,double gpa)
{
this->id=id;
this->name=name;
this->gpa=gpa;
}
string Student::getID()
{
return id;
}
string Student::getName()
{
return name;
}
void Student::changeName(string name)
{
this->name=name;
}
double Student::getGPA()
{
return gpa;
}
void Student::changeGPA(double gpa)
{
this->gpa=gpa;
}
string Student::toString()
{
stringstream ss;
  
ss << "ID: " << id << endl;
ss << "Name: " << name << endl;
ss << "GPA :" << gpa << endl;
return ss.str();
}
  


_________________________

// main.cpp

#include <iostream>
#include <fstream>
using namespace std;
#include "Student.h"

const int MAX=100;

int getStudentData(Student anArray[MAX]);
void displayMenu();
int getChoice();
int searchByID(Student aClassroster[], int size, string id);
int searchByName(Student aClassroster[], int size, string name);
bool changeStudentName(Student aClassroster[], int size, string oldName, string newName);
bool modifyStudentGPA(Student aClassroster[], int size, string id, double newGpa);
void displayAwardList(Student aClassroster[], int size, string awardType);
void displayClassRoster(Student aClassroster[], int size);
double computeAverageGPA(Student aClassroster[], int size);
int main()
{
  
string id;
int indx;
bool b;
string searchName;
Student anArray[MAX];
string oldName,newName;
int cnt=getStudentData(anArray);
while(true)
{
displayMenu();
int choice=getChoice();
switch(choice)
{
case 1:{

cout<<"Enter Student ID to Search :";
cin>>id;
int indx=searchByID(anArray,cnt,id);
if(indx==-1)
{
cout<<"Student Not Found"<<endl;
}
else
{
cout<<"Student is found at index "<<indx<<endl;
}
continue;
}   
case 2:{
cout<<"Enter Student name to Search :";
cin>>searchName;
indx=searchByName(anArray,cnt,searchName);
if(indx!=-1)
{
cout<<"Student is found at index "<<indx<<endl;
}
else
{

cout<<"Student Not Found"<<endl;
}
continue;
}   
case 3:{
cout<<"Enter Student old name you want to search with :";
cin>>oldName;
cout<<"Enter Student new name you want to replace with :";
cin>>newName;
bool b=changeStudentName(anArray,cnt,oldName,newName);
if(b)
{
cout<<"Student name is Successfully replaced"<<endl;
}
else
{
cout<<"Student name not found"<<endl;   
}
continue;
}   
case 4:{
double newGpa;
cout<<"Enter Student Id to search for :";
cin>>id;
cout<<"Enter New GPA :";
cin>>newGpa;
b=modifyStudentGPA(anArray,cnt,id,newGpa);
if(b)
{
cout<<"Student GPA is Successfully replaced"<<endl;
}
else
{
cout<<"Student name not found"<<endl;   
}
continue;
}   
case 5:{
string awardType;
cout<<"Enter award type :";
cin>>awardType;
displayAwardList(anArray,cnt,awardType);
continue;
}   
case 6:{
double avgGPA=computeAverageGPA(anArray,cnt);
cout<<"Average GPA :"<<avgGPA<<endl;
continue;
}   
case 7:{
displayClassRoster(anArray,cnt);
continue;
}   
case 8:{
cout<<":: PROGRAM EXIT ::"<<endl;
break;
}   
}
break;
}

  
  
  




  
  
  
return 0;
}
int getStudentData(Student anArray[MAX])
{
string id;
int cnt=0;
string name;
double gpa;
  
//defines an input stream for the data file  
ifstream dataIn;
//Opening the input file
dataIn.open("studentsInfo.txt");   
//checking whether the file name is valid or not
if(dataIn.fail())
{
   cout<<"** File Not Found **";
return 1;
}
else
{
while(dataIn>>id>>name>>gpa)
{
Student s(id,name,gpa);
anArray[cnt]=s;
cnt++;
}
dataIn.close();
}
return cnt;
}
void displayMenu()
{
cout<<"\n******CSE100 Course Management System*******"<<endl;
cout<<"1 - Search by ID"<<endl;
cout<<"2 - Search by name"<<endl;
cout<<"3 - Change a student name"<<endl;
cout<<"4 - Modify a student gpa"<<endl;
cout<<"5 - Display award list"<<endl;
cout<<"6 - Compute average gpa"<<endl;
cout<<"7 - Display class roster"<<endl;
cout<<"8 - Quit"<<endl;
}
int getChoice()
{
int choice;
while(true)
{
cout<<"Enter Choice :";
cin>>choice;
if(choice<1 || choice>8)
{
cout<<"** Invalid.Must be between 1-8 **"<<endl;
}
else{
break;
}
}
  
return choice;
}
int searchByID(Student aClassroster[], int size, string id)
{

for(int i=0;i<size;i++)
{
if(aClassroster[i].getID().compare(id)==0)
return i;
}   
return -1;
}
int searchByName(Student aClassroster[], int size, string name)
{
for(int i=0;i<size;i++)
{
if(aClassroster[i].getName().compare(name)==0)
return i;
}
return -1;
}
bool changeStudentName(Student aClassroster[], int size, string oldName, string newName)
{
int idx=searchByName(aClassroster,size,oldName);
if(idx==-1)
return false;
else
{
aClassroster[idx].changeName(newName);
return true;
}
}
bool modifyStudentGPA(Student aClassroster[], int size, string id, double newGpa)
{
int idx=searchByID(aClassroster,size,id);
if(idx==-1)
{
return false;
}
else
{
aClassroster[idx].changeGPA(newGpa);
return true;
}
}
void displayAwardList(Student aClassroster[], int size, string awardType)
{
if(awardType.compare("P")==0)
{
for(int i=0;i<size;i++)
{
if(aClassroster[i].getGPA()>=3.75)
{
cout<<aClassroster[i].toString();
cout<<"-------------------------"<<endl;
  
}
}
}
else if(awardType.compare("D")==0)
{
for(int i=0;i<size;i++)
{
if(aClassroster[i].getGPA()>=3.5)
{
cout<<aClassroster[i].toString();
cout<<"-------------------------"<<endl;
}
}
}
}
void displayClassRoster(Student aClassroster[], int size)
{
cout<<"\nDisplaying all Students Info :"<<endl;
for(int i=0;i<size;i++)
{
cout<<aClassroster[i].toString();
cout<<"-------------------------"<<endl;
}
}
double computeAverageGPA(Student aClassroster[], int size)
{
double sum=0;
for(int i=0;i<size;i++)
{
sum+=aClassroster[i].getGPA();
}
return sum/size;
}

__________________________

Output:


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

    A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...

  • Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.

    Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.Given files: main.cpp - contains the main function for testing the program.Course.cpp - represents a course, which contains a vector of Student objects as a course roster. (Type your code in here)Course.h - header file for the Course class.Student.cpp - represents a classroom student, which has three data members: first name, last name, and...

  • Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }:...

    Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }: Implement a void function that initiatizes a dynamic array of student records with the data stored in the file "university body.txt". The function has three formal parameters: the dynamic array "S db, the count, and the capacity. Open and close an ifstream inside the function. Remember, you must allocate memory for the initial size of the dynamic array using "new" inside this function. If...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • I need help implementing Student(const char initId [], double gpa) without using pointers. I don't know...

    I need help implementing Student(const char initId [], double gpa) without using pointers. I don't know how to initialize this with the passed in gpa value. Using C++, implement the member function specified in student.h in the implementation file, student.cpp Student(const char initId[], double gpa) { } This function will initialize a newly created student object with the passed in value. Helpful info: From student.h class Student    {    public:           Student(const char initId[], double gpa);           bool isLessThanByID(const...

  • You are to write three functions for this lab: mean, remove, display. Download the main.cpp file...

    You are to write three functions for this lab: mean, remove, display. Download the main.cpp file provided to get started. Read the comments in the main function to determine exactly what the main function should do. //include any standard libraries needed // - Passes in an array along with the size of the array. // - Returns the mean of all values stored in the array. double mean(const double array[], int arraySize); // - Passes in an array, the size...

  • The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and...

    The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and writing binary files. In this application you will modify a previous project. The previous project created a hierarchy of classes modeling a company that produces and sells parts. Some of the parts were purchased and resold. These were modeled by the PurchasedPart class. Some of the parts were manufactured and sold. These were modeled by the ManufacturedPart class. In this you will add a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT