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
|
#include <iostream>
#include <string>
void addTask(std::string*, bool*, int&);
void showSchedule(std::string*, bool*, int&, const char);
void changeStatus(bool*, int, const int aTop);
void displayATask(const std::string*, const bool*, const int);
const int no_tasks{100};
int main()
{
// SETUP DATA MODEL
int current_size{0};
std::string daily_schedule[no_tasks]{};
bool complete[no_tasks]{false};
// GENERATE SOME TASKS
for(int i = 0; i < 3; i++)
addTask(daily_schedule, complete, current_size);
std::cout << '\n';
char status{};
status = 'A'; // fo All
// PLAY AROUND ...
// (A)
showSchedule(daily_schedule, complete, current_size, status);
// (B)
changeStatus(complete, 1, current_size);
showSchedule(daily_schedule, complete, current_size, 'A');
// (C)
status = 'I'; // for Incomplete
showSchedule(daily_schedule, complete, current_size, status);
addTask(daily_schedule, complete, current_size);
status = 'A';
showSchedule(daily_schedule, complete, current_size, status);
// (D)
status = 'C'; // for Incomplete
showSchedule(daily_schedule, complete, current_size, status);
return 0;
}
void addTask(std::string* aSchedule, bool* aComplete, int& aTop)
{
std::cout << "Enter task: ";
std::string aTask;
getline(std::cin,aTask);
aSchedule[aTop] = aTask;
aComplete[aTop] = false;
aTop++;
return;
}
void showSchedule
(std::string* aSchedule, bool* aComplete, int& aTop, char aStatus)
{
for(int i = 0; i < aTop; i++)
{
if(aStatus == 'A')
displayATask(aSchedule, aComplete, i);
if(aStatus == 'C')
if( aComplete[i] == true)
displayATask(aSchedule, aComplete, i);
if(aStatus == 'I')
if( aComplete[i] == false)
displayATask(aSchedule, aComplete, i);
}
std::cout << '\n';
return;
}
void changeStatus
(bool* aComplete, int aTaskNo, const int aTop)
{
if(aTaskNo < 0 or aTaskNo > aTop )
std::cout << "ERROR: task outside range\n";
else
aComplete[aTaskNo] = !aComplete[aTaskNo];
return;
}
void displayATask
(const std::string* aSchedule, const bool* aComplete, const int aTaskNo)
{
std::cout
<< "Task no: " << aTaskNo << ' '
<< aComplete[aTaskNo] << ' '
<< aSchedule[aTaskNo] << '\n';
return;
}
| |