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
|
//Program4.cpp
#include "Program4.h"
subjectList::subjectList()
{
list = new subs[0];
numberOfSubjects = 0;
actualSize = 0;
}
void subjectList::menu()
{
int num = 0;
subjectList accessSubjects;
bool exit = false;
list = new subs[numberOfSubjects];
while (exit == false)
{
if (num == 0)
{
cout << "How many subjects do you plan on entering today?: ";
cin >> numberOfSubjects;
cin.ignore(100, '\n');
}
char response[SIZE] = " "; // I will dynamically allocate this later.
cout << "What would you like to do?\n"
<< "(\"enter subject\", \"display\", \"search\", \"remove\", or \"quit\"?)" << endl;
cin.get(response, SIZE, '\n');
cin.ignore(100, '\n');
if (strcmp(response, "enter subject") == 0)
{
if (num == 0)
{
for (int i = 0; i < numberOfSubjects; ++i)
{
accessSubjects.read(list[i]);
num++;
}
} else
{
cout << "You have already entered your subjects!" << endl;
}
}
if (strcmp(response, "display") == 0)
{
accessSubjects.display(list, num);
}
if (strcmp(response, "quit") == 0)
{
exit = true;
}
}
}
void subjectList::read(subs & subjectIn)
{
char temp[SIZE];
cout << "Please enter the subject: ";
cin.get(temp, SIZE, '\n');
cin.ignore(100, '\n');
subjectIn.subject = new char[strlen(temp) + 1];
strcpy(subjectIn.subject, temp);
cout << endl;
cout << "Please enter the description of the subject: ";
cin.get(temp, SIZE, '\n');
cin.ignore(100, '\n');
subjectIn.desc = new char[strlen(temp) + 1];
strcpy(subjectIn.desc, temp);
cout << endl;
do
{
cout << "Please enter your rating of how well you think you're doing with this subject (from 1-10): ";
cin >> subjectIn.rating;
cin.clear();
cin.ignore(100,'\n');
cout << endl;
} while (subjectIn.rating < 1 || subjectIn.rating > 10 || cin.fail());
cout << "How can you improve on this subject?: ";
cin.get(temp, SIZE, '\n');
cin.ignore(100, '\n');
subjectIn.improve = new char[strlen(temp) + 1];
strcpy(subjectIn.improve, temp);
cout << endl;
}
void subjectList::display(subs subjectIn[], int num)
{
for (int i = 0; i < num; ++i)
{
cout << subjectIn[i].subject << endl;
cout << subjectIn[i].desc << endl;
cout << subjectIn[i].rating << endl;
cout << subjectIn[i].improve << endl << endl;
}
}
|