Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using basic C++ Using Classes and the examples of the room, elevator, other func

ID: 3775634 • Letter: U

Question

Using basic C++ Using Classes and the examples of the room, elevator, other functionality we learned from Chapter 10, 11, and 12, do the following: Develop a solution for YSU that allows the student registration here at YSU. The student class should have student id (this can be an integer), first name, last name, phone, email, GPA, classrank, as a minimum set of fields. You can add more to customize it. The schedule class will have student id, class number, and credit hours as a minimum. You can add more fields if you chose. Your program should be able to add and delete students and add the students to the schedule. You do not have to create a classes class, only the schedule part to add a student and a class they are taking. Your program should be able to print out the student schedule based on a student id.

Explanation / Answer

PROGRAM CODE:

/*
* YSU.cpp
*
* Created on: 21-Nov-2016
* Author: kasturi
*/

#include <iostream>

using namespace std;

class Student
{
   //member variables for the class
private:
   int id;
   string firstName;
   string lastName;
   int phone;
   string emailID;
   float GPA;
   int classRank;
public:
   //constructor for the class
   Student(int sID, string fname, string lname, int number, string email, float gpa, int rank)
   {
       id = sID;
       firstName = fname;
       lastName = lname;
       phone = number;
       emailID = email;
       GPA = gpa;
       classRank = rank;
   }

   //getters and setters for the class
   int getClassRank() {
       return classRank;
   }

   void setClassRank(int classRank) {
       this->classRank = classRank;
   }

   string getEmailId() {
       return emailID;
   }

   void setEmailId( string emailId) {
       emailID = emailId;
   }

   string getFirstName() {
       return firstName;
   }

   void setFirstName( string firstName) {
       this->firstName = firstName;
   }

   float getGpa() const {
       return GPA;
   }

   void setGpa(float gpa) {
       GPA = gpa;
   }

   int getId() const {
       return id;
   }

   void setId(int id) {
       this->id = id;
   }

   string getLastName() {
       return lastName;
   }

   void setLastName( string lastName) {
       this->lastName = lastName;
   }

   int getPhone() {
       return phone;
   }

   void setPhone(int phone) {
       this->phone = phone;
   }

   //method to print student information
   void printStudent()
   {
       cout<<"Student ID: "<<id<<endl;
       cout<<"Student Name: "<<firstName<<" "<<lastName<<endl;
       cout<<fixed<<"Student Phone Number: "<<phone<<endl;
       cout<<"Student email ID: "<<emailID<<endl;
       cout<<"Student GPA: "<<GPA<<endl;
       cout<<"Student Rank: "<<classRank<<endl;
   }
};

class Schedule
{
private:
   int StudentID;
   int classNumber;
   int creditHours;

public:
   //constructor for the class
   Schedule(int id, int number, int hours)
   {
           StudentID = id;
           classNumber = number;
           creditHours = hours;
   }

   //getters and setters for the class
   int getClassNumber() {
       return classNumber;
   }

   void setClassNumber(int classNumber) {
       this->classNumber = classNumber;
   }

   int getCreditHours() {
       return creditHours;
   }

   void setCreditHours(int creditHours) {
       this->creditHours = creditHours;
   }

   int getStudentId() {
       return StudentID;
   }

   void setStudentId(int studentId) {
       StudentID = studentId;
   }

   void printSchdule()
   {
       cout<<"Student ID: "<<StudentID<<endl;
       cout<<"Class Number: "<<classNumber<<endl;
       cout<<"Credit Hours:"<<creditHours<<endl<<endl;
   }
};

//pointer variables for holding the student and schedule information
Student ** students = new Student*[20];
Schedule ** schedules = new Schedule*[20];
//counters for student and schedule class
int numberOfStudents = 0;
int numberOfSchedules = 0;

//method to add a student
void addStudent()
{
   int id, number, rank;
   float gpa;
   string fname, lname, email;
   cout<<" Enter student ID: ";
   cin>>id;
   cout<<" Enter student first name: ";
   cin>>fname;
   cout<<" Enter student last name: ";
   cin>>lname;
   cout<<" Enter student phone number: ";
   cin>>number;
   cout<<" Enter student email ID: ";
   cin>>email;
   cout<<" Enter student GPA: ";
   cin>>gpa;
   cout<<" Enter student rank: ";
   cin>>rank;
   students[numberOfStudents] = new Student(id, fname, lname, number, email, gpa, rank);
   numberOfStudents++;

}

//method to delete a student
void deleteStudent()
{
   int studentID;
   cout<<" Enter the student id to delete: ";
   cin>>studentID;
   for(int i=0; i<numberOfStudents; i++)
   {
       if(students[i]->getId() == studentID)
       {
           if(i+1 == numberOfStudents)
           {
               delete students[i];
               numberOfStudents--;

           }
           else
           {
               for(int j=i; j<numberOfStudents; j++)
               {
                   students[i] = students[i+1];
               }
               numberOfStudents--;
               break;
           }
       }
   }
}

//method to print the student information based on student id
void printStudentInfo(int id)
{
   bool isStudentAvailable = false;
   for(int i=0; i<numberOfStudents; i++)
   {
       if(students[i]->getId() == id)
       {
           students[i]->printStudent();
           isStudentAvailable = true;
       }
   }
   if(isStudentAvailable == false)
   {
       cout<<" No such student available";
   }
}

//method to print the schedule based on student id
void printScheduleforStudentID()
{
   int studentID;
   cout<<" Enter the student ID to get the schedule: ";
   cin>>studentID;
   bool isSchudulePrinted = false;
   for(int i=0; i<numberOfSchedules; i++)
   {
       if(schedules[i]->getStudentId() == studentID)
       {
           schedules[i]->printSchdule();
           printStudentInfo(studentID);
           isSchudulePrinted = true;
       }
   }
   if(!isSchudulePrinted)
   {
       cout<<" No Schedule found for the student";
   }
}
//method to add a student into the schedule
void addStudentToSchedule()
{
   int studentID, classNumber, creditHours;
   cout<<" Enter the Student id to add to the Schedule: ";
   cin>>studentID;
   cout<<" Enter the class number: ";
   cin>>classNumber;
   cout<<" Enter the credit hours for the student: ";
   cin>>creditHours;
   schedules[numberOfSchedules] = new Schedule(studentID, classNumber, creditHours);
   numberOfSchedules++;
}

//main function
int main()
{

   students[0] = new Student(1001, "Mike", "Ross", 98764321, "abc@xmail.com", 7.6, 20);
   numberOfStudents++;
   char choice = 'Y';
   while(choice == 'y' || choice == 'Y')
   {
       int option;
       cout<<" Choose an option. 1. Add a student 2. Add a student to schedule 3. Display a schedule for student 4. Display a student 5. Delete a student 6. Exit";
       cout<<" Enter your choice: ";
       cin>>option;
       switch(option)
       {
       case 1: addStudent();
               cout<<" Do you want to continue: Y or N? ";
               cin>>choice;
               break;
       case 2: addStudentToSchedule();
               cout<<" Do you want to continue: Y or N? ";
               cin>>choice;
               break;
       case 3: printScheduleforStudentID();
               cout<<" Do you want to continue: Y or N? ";
               cin>>choice;
               break;
       case 4: int id;
               cout<<" Enter student id: ";
               cin>>id;
               printStudentInfo(id);
               cout<<" Do you want to continue: Y or N? ";
               cin>>choice;
               break;
       case 5: deleteStudent();
               cout<<" Do you want to continue: Y or N? ";
               cin>>choice;
               break;
       case 6: exit(0);

       }
   }
   return 0;
}

OUTPUT:

Choose an option.

1. Add a student

2. Add a student to schedule

3. Display a schedule for student

4. Display a student

5. Delete a student

6. Exit

Enter your choice: 1

Enter student ID: 1002

Enter student first name: Henry

Enter student last name: Marshal

Enter student phone number: 2895756

Enter student email ID: henry@xmail.com

Enter student GPA: 8.9

Enter student rank: 6

Do you want to continue: Y or N? Y

Choose an option.

1. Add a student

2. Add a student to schedule

3. Display a schedule for student

4. Display a student

5. Delete a student

6. Exit

Enter your choice: 2

Enter the Student id to add to the Schedule: 1001

Enter the class number: 2001

Enter the credit hours for the student: 40

Do you want to continue: Y or N? Y

Choose an option.

1. Add a student

2. Add a student to schedule

3. Display a schedule for student

4. Display a student

5. Delete a student

6. Exit

Enter your choice: 3

Enter the student ID to get the schedule: 1001

Student ID: 1001

Class Number: 2001

Credit Hours:40

Student ID: 1001

Student Name: Mike Ross

Student Phone Number: 98764321

Student email ID: abc@xmail.com

Student GPA: 7.600000

Student Rank: 20

Do you want to continue: Y or N? Y

Choose an option.

1. Add a student

2. Add a student to schedule

3. Display a schedule for student

4. Display a student

5. Delete a student

6. Exit

Enter your choice: 1

Enter student ID: 1003

Enter student first name: Liam

Enter student last name: Hemsworth

Enter student phone number: 120751674

Enter student email ID: liam@xmail.com

Enter student GPA: 6.7

Enter student rank: 24

Do you want to continue: Y or N? Y

Choose an option.

1. Add a student

2. Add a student to schedule

3. Display a schedule for student

4. Display a student

5. Delete a student

6. Exit

Enter your choice: 4

Enter student id: 1003

Student ID: 1003

Student Name: Liam Hemsworth

Student Phone Number: 120751674

Student email ID: liam@xmail.com

Student GPA: 6.700000

Student Rank: 24

Do you want to continue: Y or N? Y

Choose an option.

1. Add a student

2. Add a student to schedule

3. Display a schedule for student

4. Display a student

5. Delete a student

6. Exit

Enter your choice: 5

Enter the student id to delete: 1001

Do you want to continue: Y or N? Y

Choose an option.

1. Add a student

2. Add a student to schedule

3. Display a schedule for student

4. Display a student

5. Delete a student

6. Exit

Enter your choice: 4

Enter student id: 1001

No such student available

Do you want to continue: Y or N? N

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote