Question
What I need is to make the size defined by the user (c++). Everything else works fine. #define _CRT_SECURE_NO_WARNINGS #include #include #include //library that helps
What I need is to make the size defined by the user (c++). Everything else works fine.
#define _CRT_SECURE_NO_WARNINGS #include
using namespace std;
int counter = 0; // changed the name to count as iostream has a counter that already exist const int SIZE = 10; //added this line
//Structures Declaration struct Date { int day; int month; int year; };//end of struct Date
struct Student { string id; string name; char gender; Date dob; double score; char grade; //computed by an internal function } st[SIZE]; //global array of struct Student
//Functions Prototypes
void read_file(); //function that reads from the file void save_file(); //function that saves to file void generate_stats();
int menu(); char compute_grade(double score);
void add_record(); void delete_record(); void update_record(); void sort_records();
bool emptyArray(); int find_max(); int search(); void search(char gender);
void show_record(int i); void print_records(); void print_records(int month); void print_records(char grade);
int main() { const int SIZE = 20; int choice;
read_file(); //function that will read from the file
//Show a menu to the user do { choice = menu();
switch (choice) { case 1: //Add new student if (counter < SIZE) add_record(); else cout << " ERROR: The array is full.You need to delete items first!"; break;
case 2: //delete a student if (!emptyArray()) delete_record(); break;
case 3: //update student's score if (!emptyArray()) update_record(); break;
case 4: //print all records if (!emptyArray()) print_records(); break;
case 5: //find the max score if (!emptyArray()) { int i = find_max(); show_record(i); }//end if break;
case 6: //find a student by ID if (!emptyArray()) { int i = search(); if (i >= 0) show_record(i); else cout << " Not found!! "; }//end if break;
case 7: //sort records by scores if (!emptyArray()) sort_records(); break;
case 8: //Show students by grade if (!emptyArray()) { char grade; cout << " Please enter a grade (A/B/C/D/F): "; cin >> grade; //add do while and check later print_records(grade); }//end if break;
case 9: //Show students by gender if (!emptyArray()) { char gender; //add do-while to ensure input either M or F cout << " Please enter the gender (M/F): "; cin >> gender; search(gender); }//end if break;
case 10: //Show students born in the same month if (!emptyArray()) { int month; //add do-while to ensure input in range 1 - 12 cout << " Please enter a month (1 - 12): "; cin >> month; print_records(month); }//end if break;
case 11: cout << " Thanks for using our program! "; break;
default: cout << " Incorrect menu option."; }//end switch
} while (choice != 11);
save_file(); //save to file when done generate_stats(); //save file stats
return 0; }//end of main
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