Question
/* 1) Write validation for student names that reject strings with odd chars like % or @ You may use c_str, isalpha(), and ispace() functions
/*
1) Write validation for student names that reject strings with odd chars like % or @
You may use c_str, isalpha(), and ispace() functions from c-string and string classes/libraries.
2) Write a function to validate grade data (boolean?)
*/
#include
using namespace std;
class Student{
public:
string name;
int ID;
int score;
string grade;
void setStudent(string name, int ID, int score);
};
// Class member function to enter the details
void Student :: setStudent(string name, int ID, int score){
this -> name = name;
this -> ID = ID;
this -> score = score;
// Score to grade conversion
if(score<=100 && score>=93)
this -> grade = "A";
if(score<=92 && score>=90)
this -> grade = "A-";
if(score>=87 && score<=89)
this -> grade = "B+";
if(score>=83 && score<=86)
this -> grade = "B";
if(score>=80 && score<=82)
this -> grade = "B-";
if(score>=77 && score<=79)
this -> grade = "C+";
if(score>=73 && score<=76)
this -> grade = "C";
if(score>=70 && score<=72)
this -> grade = "C-";
if(score>=67 && score<=69)
this -> grade = "D+";
if(score>=60 && score<=66)
this -> grade = "D";
if(score>=0 && score<=59)
this -> grade = "F";
}
int main(){
int i=0;
vector
stack
cout << "==========================================================================================";
cout << " |This program will help you create a student roster. Simply follow the menu instructions.| ";
cout << "==========================================================================================";
while(1){
cout<<" 1.Create student record"< cout<<"2.Display student record"< cout<<"3.Update student record"< cout<<"4.Delete student record"< cout<<"5.Calculate average score of class"< cout<<"6.Exit program"< cout<<" Please select an option: "; cin>>i; cout< // The input "6" will end the process if(i==6) break; if(i==1){ Student s; //A new variable in Student format is declared string name;//Name variable int ID; //ID int score; //To store the score // Entry of student data cout<<"Enter student's name: "; cin>>name; cout< cin>>ID; cout< cin>>mark; // A new student is created and added to the vector s.setStudent(name,ID,mark); list.push_back(s); } // To display the data if(i==2){ int id; cout<<"Enter ID to display: "; cin>>id; int j=0; for(j=0; j if(list[j].ID==id){ cout<<"Student: "< cout<<"ID: "< cout<<"Score: "< cout<<"Grade: "< break; } } if(j==list.size()) cout<<"Data Not Available"< } // To update the data if(i==3){ int id; cout<<"Enter ID to update: "; cin>>id; int j=0; for(j=0; j if(list[j].ID==id){ // Finds the location of the student in the roster using student ID Student s; string name; int ID; int score; cout<<"Enter student's name: "; cin>>name; cout<<" Enter student's ID: "; cin>>ID; cout<<" Enter student's grade: "; cin>>score; s.setStudent(name,ID,score); list[j]=s; break; } } if(j==list.size()) cout<<"Data Not Available"< } // To delete a student if(i==4){ int id; cout<<"Enter ID to delete: "; cin>>id; // 1. Traverse until you find the student // 2. Stack all the students after the required student's location // 3. Pop the student to be deleted. // 4. Put back the stacked students for(int j=0; j if(list[j].ID==id){ for(int k=list.size()-1; k!=j; k--){ Student r=list[k]; list.pop_back(); stack.push(r); } list.pop_back(); while(!stack.empty()){ list.push_back(stack.top()); stack.pop(); } break; } } } // To calculate average score of students if(i==5){ int total=0; for(int j=0; j total=total+list[j].score; cout<<"Average Score: "< } } } /* Output: ========================================================================================== |This program will help you create a student roster. Simply follow the menu instructions.| ========================================================================================== 1.Create student record 2.Display student record 3.Update student record 4.Delete student record 5.Calculate average score of class 6.Exit program Please select an option: 1 Enter student's name: Felix Enter student's ID: 99693 Enter student's grade: 99 1.Create student record 2.Display student record 3.Update student record 4.Delete student record 5.Calculate average score of class 6.Exit program Please select an option: 4 Enter ID to delete: 99693 1.Create student record 2.Display student record 3.Update student record 4.Delete student record 5.Calculate average score of class 6.Exit program Please select an option: 1 Enter student's name: Pedro Enter student's ID: 99330 Enter student's grade: 98 1.Create student record 2.Display student record 3.Update student record 4.Delete student record 5.Calculate average score of class 6.Exit program Please select an option: 2 Enter ID to display: 99693 Data Not Available 1.Create student record 2.Display student record 3.Update student record 4.Delete student record 5.Calculate average score of class 6.Exit program Please select an option: 5 Average Score: 98 1.Create student record 2.Display student record 3.Update student record 4.Delete student record 5.Calculate average score of class 6.Exit program Please select an option: */
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started