Comparing user data with input data

I want to create a program to finding the free room for the exact date. For instance user enter date as 02.01.2018 and i want to compare this date with my input.txt if the date exist in txt file i want to see first row of the line that contains date. For instance my input datas are like this:
1 01.01.2018 03.01.2018 04.01.2018
2 02.01.2018 03.01.2018
And when i enter 02.01.2018 i want to see 2 and when i enter 03.01.2018 i want to see 1 and 2.

Here is my code:

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
#include <iostream>// Input&Output Stream
#include <fstream>// File Stream
#include <vector>// Vector for arrays
#include <stdlib.h>// For exit(0)
#include <math.h>// For mathematical calculations
#include <algorithm>// For sorting datas according to date
#include <sstream>
using namespace std;///\namespace std

};
struct room{
void readFromFile();
unsigned int ID;  /**< ID */
unsigned int floor; /**< floor number */
unsigned int room_number; /**< room number */
unsigned int capacity; /**< room capacity */
unsigned int price; /**< price per day for booking */
string date; /**< reservated dates for rooms */
vector< vector<string> > a;
vector< vector<string> > b;

};


string date;
void room::readFromFile(){
// Opening input file and checking is it valid
    ifstream input1("input1.txt");
     string line1;
    //for each line;
    while (getline(input1, line1)) {
        string feature1;
        stringstream stream(line1);
        vector<string> features1;
        //for each feature
        while( getline(stream, feature1, ':') ){
            features1.push_back(feature1);
        }
        a.push_back(features1);
    }
        cout << string (line1, 0, line1.length());
    ifstream input2("input2.txt");
     string line2;
    //for each line;
    while (getline(input2, line2)) {
        string feature2;
        stringstream stream(line2);
        vector<string> features2;
        //for each feature
        while( getline(stream, feature2, ':') ){
            features2.push_back(feature2);
        }
        b.push_back(features2);
    }
        cout << string (line2, 0, line2.length());
}

int main(){
room input1;
input1.readFromFile();

room input2;
input2.readFromFile();

cout << "Enter date" << endl;
cin >> date;
if(date != "01.01.2018" && date != "02.01.2018" && date != "03.01.2018" && date != "04.01.2018" && date != "05.01.2018" && date != "06.01.2018" && date != "07.01.2018" && date != "08.01.2018" && date != "09.01.2018" && date != "10.01.2018" && date != "11.01.2018" && date != "12.01.2018" && date != "13.01.2018" && date != "14.01.2018" && date != "15.01.2018"){
    cout << "wrong date" << endl;

}
return 0;
}

Last edited on
Topic archived. No new replies allowed.