Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

From your project, share an example of the program that was challenging. Describe how it works and the problems you faced. Do you still have

  • From your project, share an example of the program that was challenging.
  • Describe how it works and the problems you faced. Do you still have the identified problem(s)? The program excerpt that you shared can be working or still needs changes. This is a great time to get help and fix your program.

Student Management System Project

#include #include #include #include

using namespace std;

struct Student { string name; int studentNumber; string email; string DOB; double GPA; string subjects[5]; // Array to store the student's subjects };

bool isValidName(const string& name) { for (char c : name) { if (!isalpha(c) && !isspace(c)) { return false; } } return true; }

void addStudent(vector& students) { Student newStudent; cout << "Enter student number: "; cin >> newStudent.studentNumber; // Clear the input buffer cin.ignore(numeric_limits::max(), ' ');

do { cout << "Enter name (first Name): "; getline(cin, newStudent.name); cout << "Enter name (Last Name): "; getline(cin, newStudent.name); if (!isValidName(newStudent.name)) { cout << "Invalid name. Please use alphabetic characters and spaces only." << endl; } } while (!isValidName(newStudent.name));

cout << "Enter email: "; cin >> newStudent.email;

cout << "Enter date of birth: "; cin >> newStudent.DOB;

cout << "Enter GPA: "; cin >> newStudent.GPA; students.push_back(newStudent);

// Add subjects to the student's array for (int i = 0; i < 5; i++) { cout << "Enter subject " << i + 1 << ": "; cin >> newStudent.subjects[i]; students.push_back(newStudent);

}

cout << "Student added successfully!" << endl;

}

void deleteStudent(vector& students) { int studentNumber; cout << "Enter student number to delete: "; cin >> studentNumber; bool found = false; for (auto it = students.begin(); it != students.end(); it++) { if (it->studentNumber == studentNumber) { students.erase(it); found = true; break; } } if (found) { cout << "Student deleted successfully!" << endl; } else { cout << "Student not found!" << endl; } }

void updateStudent(vector& students) { int studentNumber; cout << "Enter student number to update: "; cin >> studentNumber; bool found = false; for (auto& student : students) { if (student.studentNumber == studentNumber) { cout << "Enter new name: "; getline(cin, student.name); cout << "Enter new email: "; getline(cin, student.email); cout << "Enter new date of birth: "; getline(cin, student.DOB); cout << "Enter new GPA: "; cin >> student.GPA; found = true; break; } } if (found) { cout << "Student updated successfully!" << endl; } else { cout << "Student not found!" << endl; } }

void showAllStudents(const vector& students) { for (const auto& student : students) { cout << "Name: " << student.name << endl; cout << "Student number: " << student.studentNumber << endl; cout << "Email: " << student.email << endl; cout << "Date of birth: " << student.DOB << endl; cout << "GPA: " << student.GPA << endl; } }

int main() { vector students; char input; do { cout << "Menu:" << endl; cout << "A - Add student" << endl; cout << "D - Delete student" << endl; cout << "U - Update student" << endl; cout << "S - Show all students" << endl; cout << "Q - Quit" << endl; cout << "Enter your choice: "; cin >> input; switch (input) { case 'A': addStudent(students); break; case 'D': deleteStudent(students); break; case 'U': updateStudent(students); break; case 'S': showAllStudents(students); break; case 'Q': cout << "Quitting program..." << endl; break; default: cout << "Invalid choice, please try again!" << endl; break; } } while (input != 'Q'); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions