unknown crit error

Hi i am busy with a project ATM, and i get a crit error at a certain place all the time, it is marked in the source code


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Driver.h"


//NOTE Flight.h file is not needed because i do not reference to it from this file

int main()
{
    //Initilize the Program
    Read();
    Menu();
    //no need for a pause function because it is part of the Quit() function
    return 0;
}


Driver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//#ifndef GUARD_Driver_h
#define GUARD_Driver_h
//this is all the Include statements, that is needed for the project
//does not need to be per page, can also be taken from a header.
#include <cstdlib>
#include <vector>
#include <cctype>
#include <fstream>
#include <map>
#include <stdexcept>
#include <iostream>
#include <numeric>


//The functions in Driver.cpp
void Read();
void Menu();
std::vector <std::string> split(const std::string& str);
bool not_space(char c);
bool space(char c);
bool EOF_test(std::string x); 
void Option(int& o);
void errorCheck(std::string& input);
void displayAll();
void displayOne();
void updateRecord();
void addRecord();
void updateRecord();

Flight.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef GUARD_Flight_h
#define GUARD_Flight_h

#include <string>
#include <iostream>
#include <cctype>
#include <vector>

;
using namespace std;

class Flight
{
      string country;
      string city;
      string airport;
      int duration;
      double cost;
      
      public:
             void setCountry(string tempCountry)
             {
                  country = tempCountry;
             }
             
             void setCity(string tempCity)
             {
                  city = tempCity;
             }
                  
             void setAirport(string tempAirport)
             {
                  airport = tempAirport;
             }
             
             void setDuration(int tempDuration)
             {
                  duration = tempDuration;
             }
             
             void setCost(double tempCost)
             {
                  cost = tempCost;
             }
             
             void display() const
             {
                  cout << "Country: " << country
                  << "\nCity: " << city
                  << "\nAirport: " << airport
                  << "\nDuration: " << duration
                  << "\nCost: " << cost << "\n";
             }
             
             void setRecord(string tempCountry, string tempCity, string tempAirport, int tempDuration, double tempCost)
             {
                   country = tempCountry;
                   city = tempCity;
                   airport = tempAirport;
                   duration = tempDuration;
                   cost = tempCost;
             }
             
             string getCountry() const
             {
                    return country;
             }
             
             string getCity() const
             {
                    return city;
             }  
              
             string getAirport() const
             {
                    return airport;
             }     
             
             int getDuration() const
             {
                 return duration;
             }
             
             double getCost() const
             {
                    return cost;
             }
};

typedef std::map<std::string, Flight> inMap;
typedef std::map<std::string, inMap> outMap;

      
int option = 0;
vector<Flight> flight;
Flight record;
map<string , map< string, Flight > > Flights;

int quit = 0

#endif 


Next post has the driver.cpp file not enough space here
PART 1
driver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221


#include "Driver.h"
#include "Flight.h"
;

using std::cout;                using std::cin;
using std::endl;                using std::string;
using std::vector;              using std::map;

void updateRecord(outMap::const_iterator n, string& city);

std::string v; //has to be string value because m is also a selection, therefore cant be int
int succes = 0;
void Read()
{
     std::ifstream infile("data.txt");
     string info;
     vector<string> temp;
     while(getline(infile, info))
     {
           if(info == " ")
           {
                   cout << "No data has been found \nGoing to Menu\n" << endl;
                   system("pause");
                   Menu();
           }else{
                 succes = 1;
                 temp = split(info);
                 record.setRecord(temp[0], temp[1], temp[2], atoi(temp[3].c_str()), atoi(temp[4].c_str()));
                 Flights[record.getCountry()][record.getCity()] = record;
                
                 
                 }
           }
           if(succes == 1)
           {
           cout << "Load was Succesful, Launching Menu" << endl;           
           system("pause");
           system("cls");
           }           
}

void Menu()
{
     cout << "#############################" << endl;
     cout << "#            Menu           #" << endl;
     cout << "#############################" << endl;
     cout << "1) Display all records" << endl;
     cout << "2) Display one record" << endl;
     cout << "3) Add record" << endl;
     cout << "4) Update record" << endl;
     cout << "5) Delete record" << endl;
     cout << "6) Save changes" << endl;
     cout << "7) Calculate average age" << endl;
     cout << "8) Calculate average weight" << endl;
     cout << "0) Exit program" << endl;
     cout << "\nOption: ";
     cin.clear();
     
     getline(cin, v);
     
     if(EOF_test(v) == true)
     {
                    system("cls");
                    Menu();
     }
     
     errorCheck(v);
}                 

void errorCheck(string& input)
{
     if(input == "0")
     {
              Option(quit);
     }
     if(input == "m" || input == "M")
     {
             system("cls");
             Menu();
     }
     
      try
      {
        option = atoi(input.c_str());
        if(option == 0)
        {
            throw std::domain_error( "You have performed an illegal operation, Please try again. . ." );
        } 
      }
      catch(std::domain_error e){
        system("CLS");
        cout << e.what() << endl;
        Menu();  
    }
    Option(option);
}
     
void Option(int& o)
{
     system("cls");
     switch(o)
     {
              case 1:
                   cout << "Displaying all the records" << endl;
                   displayAll();
                   system("pause");
                   break;
              case 2:
                   cout << "Displaying a Selective record" << endl;
                   displayOne();
                   break;
              case 3:
                   cout << "Adding a flight record" << endl;
                   addRecord();
                   break;
               default:
                       //in case a input does not match the options avalible
                       cout << "Not a valid option \nBack to main menu" << endl;
                       cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
                       //restarting the menu function
                       Menu();
     }
}


void displayAll()
{
     //create a size type to measure the size of the map
     outMap::size_type count = 0;
     //printing all of the data in the file
     for(outMap::const_iterator itx = Flights.begin(); itx != Flights.end(); ++itx)
     {
     for(inMap::const_iterator ity = itx->second.begin(); ity != itx->second.end(); ++ity)
     {
            ity->second.display();
            cout << endl;
            count++;
        } 
     }
     cout << "Thats all the Flight Records." << endl;
     //pausing the program for the user to read all the data that is showing
     system("PAUSE");
     system("cls");
     //returnign to the menu
     Menu();
}

void displayOne()
{
     int x = 2;
     //creating a size type to make sure that errors don't occur
     outMap::size_type num_Flights = 0;
     cout << "Please enter country, m: to go back to menu: ";
     string search = " ";
     //getting inputted data
     getline(cin, search);
     //making sure an EOF input wasn't inputted
     if((EOF_test(search) == true)||(search.size() == 0)){
                          cout << "No entry \nPlease enter a country!";
                          cin.clear();
                          displayOne();
                          system("PAUSE");
                          system("CLS");
     }
     //calling the data but making sure it cannot be changed
     outMap::const_iterator country;
     inMap::const_iterator citySearch;
     string city;
     //searching the data for the inputted data
     if(Flights.find(search) != Flights.end()){
                system("CLS");
                country = Flights.find(search);
                cout << "~~~~~~~~~~~~~~~~~~~~~~~~~\n Flights Found! \n~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
                //displaying the data that matches the inputted data
                for (inMap::const_iterator ity = country->second.begin(); ity != country->second.end(); ++ity){
                    ity->second.display();
                    num_Flights++; 
                    city = ity->first;          
                } 
                //if there is more then one person with the same country the program then asks for the city
                //and searchs again this time with the city
                if(num_Flights > 1){
                              cout << "\nThere is to many Flights with that country!"
                              << "\nPlease enter city : ";
                              cin.clear();
                              getline(cin, search);
                              //making sure that there is data inputted and that an EOF wasn't inputted 
                              while((EOF_test(search) == true)||(search.size() == 0)|| country->second.find(search) == country->second.end()){
                                                      cout << "Invalid option!" << endl;
                                                      cin.clear();
                                                      cout << "Please enter city :" ;
                                                      getline(cin, search);    
                }
                if(country->second.find(search) != country->second.end()){
                    citySearch = country->second.find(search);
                }
                system("CLS");
                //printing the requested data for the user to view
                cout << "~~~~~~~~~~~~~~~\n Person found! \n~~~~~~~~~~~~~~~" << endl;
                for (inMap::const_iterator ity = country->second.begin(); ity != country->second.end(); ++ity){
                    if(citySearch == ity){
                        ity->second.display();
                        city = ity->first;
                    }
                }
            }
 }else if(search == "m"|| search == "M"){
           system("CLS");
           //returning to the menu
           Menu();
     }else{
           //printing error when the search does not match
           cout << "No such record exsists!\n";
           //rerunning the program
           displayOne();
     }
     //running the endtest function to check if the user wants to do the action again
     system("pause");
     }




part 2 of same file now
Last edited on
part2
driver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171


void addRecord()
{
     int x = 3;
     //printing intructions to the user
     cout << "\nPlease input the flight details: <country> <city> <airport> <duration> <cost>"
     << "\neg. America NY NYairport 8 87.40" <<endl;
     
     //reading the data inputted
     getline(cin, v);
     //checking if the user has chosen to go back to the menu
     if (v == "M" || v == "m"){
        system("CLS");
        //running the menu function
        Menu();
        //testing for an EOF input
     }else if(EOF_test(v) == true){
        system("CLS");
        //running the function again
        addRecord();
        system("PAUSE");
        //checking if the user has inputted data
     }else if(v.size() == 0){
        cout << "Error.> you have to input something!!" << endl;
        //if not the function is re run
        addRecord();   
        system("PAUSE");
     }else{
           //splitting the data inputted and loading it into a vector
        vector<string> tempV = split(v);
        //making sure that all the data has been inputted
        if(tempV.size() != 5){
            cout << "Error.> You haven't inputted all the data \n" << endl;
            //if not rerunning the addRecord function
            addRecord();     
            system("PAUSE");
        }
        //collecting the data in its respective places
        vector<string>::size_type temp1 = atoi(tempV[3].c_str());
        vector<string>::size_type temp2 = atoi(tempV[4].c_str());
        system("pause");
        system("pause");
        outMap::const_iterator country = Flights.find(tempV[0]);
        system("pause");
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
        inMap::const_iterator city = country->second.find(tempV[1]);
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
        system("pause");
        int hi = 0;
        //making sure there is space
        system("pause");

        if( country != Flights.end()){
            //checking if the persons name already exsists
            if (city != country->second.end()){
                while(hi == 0){
                         system("pause");
                         //printing an error that someone of the same name is already inputted
                         cout << "\nError.> There is already a person with that name  " << endl;
                         cout << "\nDo you wish to update this persons record?" << endl;
                         //asking if the user wants to update the persons data
                         cout << "\ny: yes \nn: no \nm: menu" << endl;
                         string aws = " ";
                         //clearing the input to avoid errors
                         cin.clear();
                         //reading the inputted data
                         getline(cin, aws);
                         if(aws == "y" || aws == "Y"){
                                system("CLS");
                                //in the case that they want to update that person the choice is changed then the update is run
                                option = 4;
                                displayOne();
                         }else if(aws == "n" || aws == "N"){
                               system("cls");
                               //if they choose not to update they return the the addRecord function
                               addRecord();
                         }else if(aws == "m" || aws == "M"){
                               system("CLS");
                               //return user to menu
                               Menu();
                         }else{
                               //in the case that the user does not put in the correct options avalible an error is printed
                               cout << "/nNot a valid option" << endl;
                               system("CLS");
                         }
                }
                
                //returning to the addRecord function
                addRecord();
            } 
        }    
        //making sure that the data is in the correct range and notout of preportion 
        if((tempV.size() == 5) && (temp1 != 0 && temp1 > 0 && temp1 < 100 ) && 
           (temp2 != 0 && temp2 > 0)){
            //once correct the data is then added to the map
            record.setRecord(tempV[0], tempV[1], tempV[2], temp1 , temp2) ; 
            Flights[record.getCountry()][record.getCity()] = record;
            cout << "\nData Added!" << endl;
            //it is then autosaved in case the computer shuts down without saving the data
            std::ofstream outfile("data.txt");
            for(outMap::const_iterator out = Flights.begin(); out != Flights.end(); ++out){
                for(inMap::const_iterator in = Flights[out->first].begin(); in != Flights[out->first].end(); ++in){
                                          outfile << out->first << " " <<  in->first << " " << in->second.getAirport() << " " << in->second.getDuration() << " " << in->second.getCost() << endl;        
                }   
            }
            //checking if the user wishes to add another Flight
        }else{
            //printing the error that occured if any
            cout << "\nData inputted wrong or wrong data inputted. \nEnter Data again \n\n" << endl;
            //starting the addRecord function again so that correct data is inputted
            
            addRecord();
            
        }
    }
}

bool EOF_test(string x)            
{
    //this entire funtion is to make sure that an EOF input is not allowed
    //checking the input if it is an EOF input
    if(cin.eof()){
        //if so an error is printed for the user to see
        cout << "ctrl + z not allowed" << endl;
        //the input is cleared to avoid any errors
        cin.clear();
        system("PAUSE");
        //returns a true value
        return true;
    }
    //returns a false value in the case that an EOF is not inputted
    return false;
}


bool space(char c)
{
    //checking if the character is a space
    return isspace(c);    
}


bool not_space(char c)
{
    //checking if the data is not a space
    return !isspace(c);   
}


vector <string> split(const string& str)
{
    typedef string::const_iterator iter;
    vector<string> ret;
    
    iter i = str.begin();
    while(i != str.end()){
        //ignoring the blanks
        i = find_if(i, str.end(), not_space);
        //finding the end of the next word
        iter j = find_if(i, str.end(), space);
        if(i != str.end()){
            //copying the word
            ret.push_back(string(i, j));
            i = j;
        }
    }
    return ret;
}


Now the problem has been marked off in the code. line 48 of part 2

when u input option 3 and try to input data it gives crit error when tring to store string data
Last edited on
Topic archived. No new replies allowed.