help needed !!

i am working on reminder/to do list program . i am not able to finish it .. the data's are given which is in main function .. so when the data is inputted , the data should match the data which is given in main function with its message , date and time ..
the time is declared from 0 to 23 for hours and 0 - 59 for minutes . so when the user enters the number other than given numbers say (24forhours ) that function should ask the user enter the hours again since the hours can be given only between 0 - 23 . i dont know how to do that .The function it is in time class . input()






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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//

#include <iostream>

using namespace std;

void remindersList();
void deleteReminder();


class memo
{
public:
    
    string message;
    int date;
    int time;
    
    void displayItems();
    void outputLongFormat();
    void outputShortFormat();
    
}
memoObject[4];


void memo::displayItems()
{
    
    cout<<"\n"<<memoObject[0].message<<endl;
    cout<<memoObject[0].date<<","<<memoObject[0].time<<endl;
    
    int select;
    
    cout<<"\nPress 1 to view all the reminders"<<endl;
    cin>>select;
    
    switch (select)
    {
        case 1:
            remindersList();
            break;
            
        default:displayItems();
            break;
    }
}

void remindersList()
{
    for (int i=0; i<=3; i++)
    {
        cout<<"\n"<<memoObject[i].message<<"  "<<memoObject[i].date<<"  "<<memoObject[i].time<<endl;
    }
}

//void deleteReminder()
//{
//   
//    int memoObjectCount;
//    for (int i=0; i<memoObjectCount; i++)
//    {
//        memoObject[i].message=" ";
//        memoObject[i].date=" ";
//        memoObject[i].time=" ";
//        memoObjectCount=0;
//    }
//    
//}

class date
{
    public:
    
    memo memoObject[4];
    int day;
    int month;
    int year;
    
    void input();
    void displayLongFormat();
    void displayShortFormat();
    
}dateObject;


void date::input()
{
    
    cout<<"\nEnter Year"<<endl;
    cin>>year;
    
    cout<<"\nEnter day"<<endl;
    cin>>day;
    
    cout<<"\nSelect the month"<<endl;
    
    cout<<"\n1.Jan"<<endl;
    cout<<"2.Feb"<<endl;
    cout<<"3.Mar"<<endl;
    cout<<"4.Apr"<<endl;
    cout<<"5.May"<<endl;
    cout<<"6.June"<<endl;
    cout<<"7.July"<<endl;
    cout<<"8.Aug"<<endl;
    cout<<"9.Sept"<<endl;
    cout<<"10.Oct"<<endl;
    cout<<"11.Nov"<<endl;
    cout<<"12.Dec\n"<<endl;
    
    cin>>month;
    
}


void date::displayLongFormat()
{
    switch (month)
    {
        case 1:
            cout<<day<<" "<<"Jan"<<" "<<year<<endl;
            break;
        case 2:
            cout<<day<<" "<<"Feb"<<" "<<year<<endl;
            break;
        case 3:
            cout<<day<<" "<<"Mar"<<" "<<year<<endl;           
            break;
        case 4:
            cout<<day<<" "<<"Apr"<<" "<<year<<endl;    
            break;
        case 5:
            cout<<day<<" "<<"May"<<" "<<year<<endl;        
            break;
        case 6:
            cout<<day<<" "<<"June"<<" "<<year<<endl;
            break;
        case 7:
            cout<<day<<" "<<"July"<<" "<<year<<endl;
            break;
        case 8:
            cout<<day<<" "<<"Aug"<<" "<<year<<endl;
            break;
        case 9:
            cout<<day<<" "<<"Sept"<<" "<<year<<endl;
            break;
        case 10:
            cout<<day<<" "<<"Oct"<<" "<<year<<endl;
            break;
        case 11:
            cout<<day<<" "<<"Nov"<<" "<<year<<endl;
            break;
        case 12:
            cout<<day<<" "<<"Dec"<<" "<<year<<endl;
            break;
            
        default:displayLongFormat();
            break;
    }
}


void date::displayShortFormat()
{
    cout<<day<<"/"<<month<<"/"<<year<<endl;
}


class time
{
    public:
    int hour;
    int min;
     
    void input();
    void output();
    
}timeObject;


void time::input()
{
    cout<<"\nEnter hour"<<endl;

    for (int i=0; i<=23; i++)
    {
        if (hour==i)
        {
            cin>>hour;
        }
        else
        {
            input();
        }
    }
    cout<<"\nEnter min"<<endl;
    cin>>min;
}


void time::output()
{
    cout<<hour<<":"<<min<<endl;
}
[/b]

int main (int argc, const char * argv[])
{

    memoObject[0].message="Go and get milk";
    memoObject[0].date=2852011;
    memoObject[0].time=140;
    
    memoObject[1].message="Drink Tea";
    memoObject[1].date=2852011;
    memoObject[1].time=200;
    
    memoObject[2].message="Sleep";
    memoObject[2].date=2852011;
    memoObject[2].time=300;
    
    memoObject[3].message="Watch IPL";
    memoObject[3].date=2852011;
    memoObject[3].time=600;

  
    memoObject[0].displayItems();

    
    dateObject.input();
    dateObject.displayLongFormat();
    dateObject.displayShortFormat();
    timeObject.input();
    timeObject.output();
    
    
}



Last edited on
if I understand you can do something like that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void time::input()
{
    cout<<"\nEnter hour"<<endl;

//idea:
do{  
            cin>>hour;
}while(hour>23 || hour <0)
      

    cout<<"\nEnter min"<<endl;
//do the same before:
    cin>>min;
}
i think it should be
 
while(hour>0 || hour<23)


since it should be b/w 0 and 23 not more than 23 :)

did u got the idea about the other problem which i am facing ??
I think my ask is correct:

1
2
3
4
do{  
            //cout <<"put a correct hour" << endl;
            cin>>hour;
}while(hour>23 || hour <0)


While the user dont put a correct answer your program will still ask a good answer.


About the other program I'm not sure what is your problem, my english isn't too good if you could explain it slowly.
there is one more problem in output window the date format should be 28 may 2011 and when the user enters 1 to view all the reminders the date format should be 28/5/2011 .

i have to use objects within objects dont know how to do that



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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include <iostream>

using namespace std;

void remindersList();
void deleteReminder();


class memo
{
public:
    
    string message;
    int date;
    int time;
    
    void displayItems();
    void outputLongFormat();
    void outputShortFormat();
    
}
memoObject[4];


void memo::displayItems()
{
    
    cout<<"\n"<<memoObject[0].message<<endl;
    cout<<memoObject[0].date<<","<<memoObject[0].time<<endl;
    
    int select;
    
    cout<<"\nPress 1 to view all the reminders"<<endl;
    cin>>select;
    
    switch (select)
    {
        case 1:
            remindersList();
            break;
            
        default:displayItems();
            break;
    }
}

void remindersList()
{
    for (int i=0; i<=3; i++)
    {
        cout<<"\n"<<memoObject[i].message<<"  "<<memoObject[i].date<<"  "<<memoObject[i].time<<endl;
    }
}

//void deleteReminder()
//{
//   
//    int memoObjectCount;
//    for (int i=0; i<memoObjectCount; i++)
//    {
//        memoObject[i].message=" ";
//        memoObject[i].date=" ";
//        memoObject[i].time=" ";
//        memoObjectCount=0;
//    }
//    
//}

class date
{
    public:
    
    memo memoObject[4];
    int day;
    int month;
    int year;
    
    void input();
    void displayLongFormat();
    void displayShortFormat();
    
}dateObject;


void date::input()
{
    
    cout<<"\nEnter Year"<<endl;
    cin>>year;
    
    cout<<"\nEnter day"<<endl;
    do {
        cin>>day;
    } while (day>31 || day<1);
    
    cout<<"\nSelect the month"<<endl;
    
    cout<<"\n1.Jan"<<endl;
    cout<<"2.Feb"<<endl;
    cout<<"3.Mar"<<endl;
    cout<<"4.Apr"<<endl;
    cout<<"5.May"<<endl;
    cout<<"6.June"<<endl;
    cout<<"7.July"<<endl;
    cout<<"8.Aug"<<endl;
    cout<<"9.Sept"<<endl;
    cout<<"10.Oct"<<endl;
    cout<<"11.Nov"<<endl;
    cout<<"12.Dec\n"<<endl;
    
    do {
        cin>>month;
    } while (month>12 || month<1);
    
}


void date::displayLongFormat()
{
    switch (month)
    {
        case 1:
            cout<<day<<" "<<"Jan"<<" "<<year<<endl;
            break;
        case 2:
            cout<<day<<" "<<"Feb"<<" "<<year<<endl;
            break;
        case 3:
            cout<<day<<" "<<"Mar"<<" "<<year<<endl;           
            break;
        case 4:
            cout<<day<<" "<<"Apr"<<" "<<year<<endl;    
            break;
        case 5:
            cout<<day<<" "<<"May"<<" "<<year<<endl;        
            break;
        case 6:
            cout<<day<<" "<<"June"<<" "<<year<<endl;
            break;
        case 7:
            cout<<day<<" "<<"July"<<" "<<year<<endl;
            break;
        case 8:
            cout<<day<<" "<<"Aug"<<" "<<year<<endl;
            break;
        case 9:
            cout<<day<<" "<<"Sept"<<" "<<year<<endl;
            break;
        case 10:
            cout<<day<<" "<<"Oct"<<" "<<year<<endl;
            break;
        case 11:
            cout<<day<<" "<<"Nov"<<" "<<year<<endl;
            break;
        case 12:
            cout<<day<<" "<<"Dec"<<" "<<year<<endl;
            break;
            
        default:displayLongFormat();
            break;
    }
}


void date::displayShortFormat()
{
    cout<<day<<"/"<<month<<"/"<<year<<endl;
}


class time
{
    public:
    int hour;
    int min;
     
    void input();
    void output();
    
}timeObject;


void time::input()
{
    cout<<"\nEnter hour"<<endl;

    do{
        cin>>hour;
    }while(hour>23 || hour<0);
        
    cout<<"\nEnter min"<<endl;
    
    do {
        cin>>min;
    } while (min>59 || min<0);
    
}

void time::output()
{
    cout<<hour<<":"<<min<<endl;
}

int main (int argc, const char * argv[])
{

    memoObject[0].message="Go and get milk";
    memoObject[0].date=2852011;
    memoObject[0].time=140;
    
    memoObject[1].message="Drink Tea";
    memoObject[1].date=2852011;
    memoObject[1].time=200;
    
    memoObject[2].message="Sleep";
    memoObject[2].date=2852011;
    memoObject[2].time=300;
    
    memoObject[3].message="Watch IPL";
    memoObject[3].date=2852011;
    memoObject[3].time=600;

  
    memoObject[0].displayItems();

    
    dateObject.input();
    dateObject.displayLongFormat();
    dateObject.displayShortFormat();
    timeObject.input();
    timeObject.output();
    
    
}
Last edited on
I suggest the inputs of your program will be strings for void error of input and after transform to int unless you use excepcions.

You could use somthing like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void date::input()
{
           ...
           int aux;

           cout << "Select 1 for see short format or any number for long"<<endl;
           cin>>aux;

           switch (aux)
          {
                case 1: displayShortFormat();
                        break;
              
               default:displayLongFormat();
                       break;
           }


}
Objects embedded within other objects is rather simple.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class A {
    public:
    int var;
    };

class B {
    public:
    A obj;
    };

int main(){
    B object;
    object.obj.var = 5;
    cout << object.obj.var << endl;
    return 0;}
hmm i have to use objects within other objects method in the program . i am not able to figure it out
parent_object.child_object.method(params);
how to add a reminder and delete a reminder .. when u add a reminder it should add message , date and time and when u delete a reminder the reminder gets deleted from the list .

how to add a message which is in string format ?

when i choose add reminder in the output the input function of date and time function is being called twice idk whats the problem in it ..


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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include <iostream>

using namespace std;

void remindersList();


class dateClass
{
    public:

    int day;
    int month;
    int year;
    
    void input();
    void displayLongFormat();
    void displayShortFormat();
    
};


void dateClass::input()
{
    
    cout<<"\n\nEnter Year : "<<endl;
    cin>>year;
    
    cout<<"\nEnter day (1-31) : "<<endl;

    do 
    {
        cin>>day;
    } 
    while (day>31 || day<1);
    
    cout<<"\nSelect the month : "<<endl;
    
    cout<<"\n1.Jan"<<endl;
    cout<<"2.Feb"<<endl;
    cout<<"3.Mar"<<endl;
    cout<<"4.Apr"<<endl;
    cout<<"5.May"<<endl;
    cout<<"6.June"<<endl;
    cout<<"7.July"<<endl;
    cout<<"8.Aug"<<endl;
    cout<<"9.Sept"<<endl;
    cout<<"10.Oct"<<endl;
    cout<<"11.Nov"<<endl;
    cout<<"12.Dec\n"<<endl;
    
    cout<<"Enter month"<<endl;
    do
    {
        cin>>month;
    }
    while (month>12 || month<1);

}


void dateClass::displayLongFormat()
{
    switch (month)
    {
        case 1:
            cout<<day<<" "<<"Jan"<<" "<<year<<endl;
            break;
        case 2:
            cout<<day<<" "<<"Feb"<<" "<<year<<endl;
            break;
        case 3:
            cout<<day<<" "<<"Mar"<<" "<<year<<endl;           
            break;
        case 4:
            cout<<day<<" "<<"Apr"<<" "<<year<<endl;    
            break;
        case 5:
            cout<<day<<" "<<"May"<<" "<<year<<endl;        
            break;
        case 6:
            cout<<day<<" "<<"June"<<" "<<year<<endl;
            break;
        case 7:
            cout<<day<<" "<<"July"<<" "<<year<<endl;
            break;
        case 8:
            cout<<day<<" "<<"Aug"<<" "<<year<<endl;
            break;
        case 9:
            cout<<day<<" "<<"Sept"<<" "<<year<<endl;
            break;
        case 10:
            cout<<day<<" "<<"Oct"<<" "<<year<<endl;
            break;
        case 11:
            cout<<day<<" "<<"Nov"<<" "<<year<<endl;
            break;
        case 12:
            cout<<day<<" "<<"Dec"<<" "<<year<<endl;
            break;
            
        default:displayLongFormat();
            break;
    }

}


void dateClass::displayShortFormat()
{
    cout<<day<<"/"<<month<<"/"<<year<<endl;
}


class timeClass
{
    public:
    int hour;
    int min;
     
    void input();
    void output();
    
};


void timeClass::input()
{
    cout<<"\nEnter hour (0-23) : "<<endl;

    do
    {
        cin>>hour;
    }
    while(hour>23 || hour<0);
        
    cout<<"\nEnter min (0-59) : "<<endl;
    
    do
    {
        cin>>min;
    }
    while (min>59 || min<0);
    
}

void timeClass::output()
{
    cout<<hour<<":"<<min<<endl;
}


class reminder
{
public:
    
    string message;
    
    void displayItems();
    void outputLongFormat();
    void outputShortFormat();
    
    dateClass date;
    timeClass time;
    
    
}reminderObject[10];

void reminder::displayItems()
{
    
    cout<<"\n"<<reminderObject[0].message<<endl;
    date.displayLongFormat(); 
    cout<<reminderObject[0].time.hour<<":"<<reminderObject[0].time.min<<endl;
    
    int select;
    cout<<"\nPress 1 to view all the reminders"<<endl;
    cin>>select;
    
    switch (select)
    {
        case 1:
            remindersList();
            break;
            
        default:displayItems();
            break;
    }
    
}

void remindersList()
{
    reminder newRem;                                 // IMPORTANT  NOTE 

    for (int i=0; i<=3; i++)
    {
        cout<<"\n"<<reminderObject[i].message<<"  "<<reminderObject[i].date.day<<"/"<<reminderObject[i].date.month<<"/"<<reminderObject[i].date.year<<","<<reminderObject[i].time.hour<<":"<<reminderObject[i].time.min;
    }
    
    int option;
    
    
    cout<<"\n\nSelect Options\n"<<endl;
    cout<<"1.Add Reminder"<<endl;
    cout<<"2.Delete Reminder"<<endl;
    cin>>option;
    
    switch (option)
    {
        case 1:
            cout<<"Enter Message :"<<endl;
            cin>>newRem.message;
            
            newRem.date.input();                    // IMPORTANT    NOTE
            newRem.time.input();                    // IMPORTANT    NOTE        
            break;
            
            
        case 2:
            break;
            
        default:remindersList();
            break;
    }
    
}




int main (int argc, const char * argv[])
{
    
    reminderObject[0].message="Go and get milk";    
    reminderObject[0].date.day=28;
    reminderObject[0].date.month=5;
    reminderObject[0].date.year=2011;
    reminderObject[0].time.hour=1;
    reminderObject[0].time.min=40;
    
    reminderObject[1].message="Drink Tea";
    reminderObject[1].date.day=28;
    reminderObject[1].date.month=5;
    reminderObject[1].date.year=2011;
    reminderObject[1].time.hour=2;
    reminderObject[1].time.min=00;
    
    reminderObject[2].message="Sleep";
    reminderObject[2].date.day=28;
    reminderObject[2].date.month=5;
    reminderObject[2].date.year=2011;
    reminderObject[2].time.hour=3;
    reminderObject[2].time.min=00;
    
    reminderObject[3].message="Watch IPL";
    reminderObject[3].date.day=28;
    reminderObject[3].date.month=5;
    reminderObject[3].date.year=2011;
    reminderObject[3].time.hour=6;
    reminderObject[3].time.min=00;

    
    reminderObject[0].displayItems();

    reminderObject[0].date.input();
    reminderObject[0].date.displayLongFormat();
    reminderObject[0].date.displayShortFormat();
        
    reminderObject[0].time.input();
    reminderObject[0].time.output();

}
Last edited on
Topic archived. No new replies allowed.