Hi, I am trying to write a program for my mum who is a teacher, the program needs to be able to store students information like their name address SAT scores etc. I have a basic background in c, but i decided to try and implement this program using c++. what i have done so far compiles but the program keeps crashing whenever i try to enter the section of the program where i have to add students into my vectors.
Here is my code
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <vector>
#include <string>
#include <fstream>
#define MAXSTUDENTS 200
using namespace std;
class Options{
public:
void welcome(void);
int main_menu(void);
Options add(void);
void search(void);
void remove(void);
void display(void);
private:
vector<Options> info;
string firstname, lastname, middlename;
int birthyear, birthmonth, birthdate;
int contacticenumber;
string contacticename;
int housenumber;
string streetname, city, postcode;
string allergies;
string SAT1, SAT2, SAT3, SAT4, SAT5, SAT6, SAT7, SAT8, SAT9;
};
void Options::welcome()
{
cout << "Welcome to the Datamaster 1.0" << endl << endl << "Please keep checking for regular software updates" << endl;
cout << "Loading ";
for (int a = 0; a < 6; a++)
{
cout << ". ";
for (int x = 0; x < 500; x ++)
{
for (int y = 0; y < 200000; y++)
{}
}
}
system("cls");
}
int Options::main_menu()
{
int selection;
char answer;
cout << "Please select from the following: " << endl << endl;
cout << "1. Search Students" << endl << "2. Add Student" << endl << "3. Remove Student" << endl << "4. Exit Program" << endl;
cin >> selection;
if (selection < 1 || selection > 4)
{
system("cls");
cout << "Sorry that was not an option, please try again\nPress any key to return to the main menu";
cin.get();
system("cls");
return Options::main_menu();
}
if (selection != 4)
{
cout << endl << "You have chosen " << selection << ", is this correct (y/n)?" << endl;
cin >> answer;
}
else
{
cout << endl << "Do you want to exit the program (y/n)?" << endl;
cin >> answer;
}
if (answer == 'y')
{
switch (selection){
case 1:
Options::search();
break;
case 2:
Options::add();
break;
case 3:
Options::remove();
break;
case 4:
return 0;
break;
}
}
else
return Options::main_menu();
return selection;
}
void Options::search()
{
/*cout<< "Searching ";
for (int a = 0; a < 6; a++)
{
cout << ". ";
for (int x = 0; x < 500; x ++)
{
for (int y = 0; y < 200000; y++)
{}
}
}*/
string lastname;
cout << "Please enter the last name of the student you are looking for: ";
cin >> lastname;
int size = Options::info.size();
cout << "The Students with that Last name are: ";
for(int i = 0; i < size; i ++)
{
if (lastname == info[i].lastname)
{
cout << info[i].firstname << info[i].lastname;
}
}
system("cls");
Options::main_menu();
}
void Options::remove()
{
cout<< "Removing ";
for (int a = 0; a < 6; a++)
{
cout << ". ";
for (int x = 0; x < 500; x ++)
{
for (int y = 0; y < 200000; y++)
{}
}
}
system("cls");
Options::main_menu();
}
Options Options::add()
{
system("cls");
int choice;
Options adding;
int size = Options::info.size();
for (int i = size; i < MAXSTUDENTS; i++)
{
cout << "Please enter the following information about the new student" << endl;
cin.get();
cout << "First name: ";
getline (cin, info[i].firstname);
cout << "Last name: ";
getline (cin, info[i].lastname);
cout << "Any middle names or middle initials: ";
getline (cin, info[i].middlename);
cout << endl;
cout << "Now please enter the students address" << endl;
cout << "House number: ";
cin >> info[i].housenumber;
cin.get();
cout << "Streetname: ";
getline (cin, info[i].streetname);
cout << "City: ";
getline (cin, info[i].city);
cout << "Postcode: ";
getline (cin, info[i].postcode);
cout << endl;
cout << "Now enter the D.O.B for the student" << endl;
cout << "Year: ";
cin >> info[i].birthyear;
cout << "Month (01-12): ";
cin >> info[i].birthmonth;
cout << "Date (01-31): ";
cin >> info[i].birthdate;
cout << "Please detail any allergies the student has separated by commas (,)" << endl;
cin.get();
cout << "Allergies: ";
getline (cin, info[i].allergies);
cout << endl;
cout << "Now enter the students emergency contact details" << endl;
cout << "I.C.E Name: ";
getline (cin, info[i].contacticename);
cout << "I.C.E Contact Number: ";
cin >> info[i].contacticenumber;
cout << endl;
break;
}
cin.get();
cout << "Student successfully added\nYou can add SAT results to this student now\nor in the edit screen" << endl;
cout << "Choose either:\n(1) to add another student\n(2) to add SAT results for this student\n(3) to return to main menu" << endl;
cin >> choice;
cout << endl;
switch (choice){
case 1:
system("cls");
Options::add();
break;
case 2:
//Add upto 9 years of SATs results
system("cls");
Options::main_menu();
break;
case 3:
system("cls");
Options::main_menu();
break;
}
return adding;
}
void Options::display ()
{
//function to display all the first and last names of all the students in the database
}
int main()
{
Options options;
options.welcome();
options.main_menu();
return 0;
}
Any help would be greatly appreciated
Thanks
Tom