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
|
#include <iostream>
using namespace std;
//constants
const int MAX_CAPACITY = 30;
const int MIN_CAPACITY = 1;
const string COURSE_NUM = " course number: ";
const string COURSE_TITLE = " course title: ";
//prototype
string messagePrompt(string);
string courseNumPrompt();
bool courseNumValidity(string);
//int capacityValidation();
// clockType class specification
class course
{
private:
string courseNum; //stores the course number (e.g. CS361)
string courseTitle; //stores the course title (e.g. "Control structures")
int capacity; //stores the capacity of the classroom in number of students
int numEnrolledStudents; //stores the number of enrolled students
int stuID [MAX_CAPACITY]; //stores the 5 digit student id, with a max of 30 in the array
public:
//constructors
course(); //Default constructor
course(string crseNum, string title, int cap); //Constructor with parameters
//mutator functions
void setCourseNum(); //manipulates data for the course number
void setCourseTitle(); //manipulates data for the course title
void setCapacity() const; //manipulates data for the classroom capacity
//Accessor functions
void getCourseNum(); //retrieves the course number
void getCourseTitle(); //retrieves the course title
void getCapacity(); //retrieves the capacity
void getNumEnrolled(); //retrieves the number of enrolled students
//facilitator functions
string printCourse(); //display course data
void printStudentIds(); //display all student ID's on student Id list
void addOneStudent(); //add one student to course
void dropOneStudent(); //drop one student from course
};
//**************************************************************************
// FUNCTION: main
// DESCRIPTION: Creates two clockType class objects and manipulates them.
// OUTPUT:
// Return Value: 0 for success
// CALLS TO: setTime, getTime, printTime, incrementSeconds,
// incrementMinutes, incrementHours, equalTime
//**************************************************************************
int main()
{
//variables
string tempCourseNum;
string tempCourseTitle;
int cap;
//constuctors
course course1("CS361", "Control Structures", MAX_CAPACITY); //constructor with parameters
course course2("CS362", "Data Structures", 10); //constructor with parameters
course course3; //default constructor
course3.setCourseNum(); //prompt and validate user for course number
course3.setCourseTitle(); //prompt user for course title
cout << endl;
//course printCourse(course1,course2,course3);
course1.printCourse ();
return 0;
}//end main
//*********************************************************************
// Function: course::course
// Description: Default constructor
// Output: course object, initialized to all 0s
//*********************************************************************
course::course()
{
courseNum = " ";
courseTitle = " ";
capacity = MIN_CAPACITY;
numEnrolledStudents = 0;
}
//****************************************************************************
// Function: course::course
// Description: Constructor with parameters
// Input: Parameters: crseNum, title, cap - course number, title, and capacity
// Output: course object, set to parameter values
//****************************************************************************
course::course(string crseNum, string title, int cap)
{
courseNum = crseNum;
courseTitle = title;
capacity = cap;
//cout << "course3 = "<< courseNum<<" " <<courseTitle<<endl;
}
//****************************************************************************
// Function: course::setCourseNum
// Description: retrieves the course number
// Input: Parameters: N/A
// Output: N/A
//****************************************************************************
void course::setCourseNum()
{
courseNum = courseNumPrompt();
//cout << "course = "<< courseNum<<endl;
}
//****************************************************************************
// Function: course::setCourseTitle
// Description: retrieves the course title
// Input: Parameters: N/A
// Output: N/A
//****************************************************************************
void course::setCourseTitle()
{
courseTitle = messagePrompt(COURSE_TITLE);
//cout << "course = " <<courseTitle<<endl;
}
//******************************************************************************
//void course::getCourseNum()
//{
//variables
// string tempCourseNum;
// tempCourseNum = courseNum;
//}
//****************************************************************************
void getCourseTitle()
{
}
//****************************************************************************
// Function: messagePrompt
// Description: prompts the message for course title
// Input: Parameters: prompt message (const)
// Output: response - returns the respnse
//****************************************************************************
string messagePrompt(string prompt)
{
//variable
string response;
cout << "Please enter the students" << prompt;
cin >> response;
return response;
}
//*************************************************************************
// FUNCTION: courseNumPrompt
// DESCRIPTION: prompts for user to inpout student ID. Calls function
// testValidity to test if the format is valid
// INPUT: NA:
// OUTPUT: return: id - returns the either NOT_FOUND (-1) or
// the array number for the target ID
//***************************************************************************
string courseNumPrompt()
{
int cnt1 = 0;
bool goodID = false;
string id = " ";
cout << endl << endl;
cout << "Enter course number (e.g. CT234): " << endl;
cin >> id;
for (cnt1; cnt1 < id.length(); ++cnt1)
id[cnt1] = toupper(id[cnt1]);
while (!goodID)
{
if (courseNumValidity(id) == true)
{
cout << endl;
cout << "INVALID ID FORMAT" << endl;
cout << "Must start with two characters (A to Z) and end with three digits" << endl;
cout << "Enter course number: " << endl;
cin >> id;
}
else
{
cout << endl;
cout << "VALID ID FORMAT" << endl;
goodID = true;
}
}
return id;
}
//*************************************************************************
// FUNCTION: courseNumValidity
// DESCRIPTION: Validates the user input for student ID
// INPUT: Parameter: id - text file to be read from
//
// OUTPUT: return: id - returns either true or false to function
// userInput
//***************************************************************************
bool courseNumValidity(string id)
{
bool invalidLetter = false;
for (unsigned int i= 0; i < id.length()-1; i++)
{
if (i < 2 && isdigit(id[i]))
invalidLetter = true;
if (i > 1 && isalpha(id[i]))
invalidLetter = true;
}
if (id.length()!= 5)
invalidLetter = true;
return invalidLetter;
}
//*****************************************************************************
string course::printCourse()
{
//variable
string crseNum1;
cout << "Choose a course to manage:" << endl;
cout << "\t" << courseNum << " - " << courseTitle<< endl;
cout << "\t" << courseNum << " - " << courseTitle<< endl;
cout << "\t" << courseNum << " - " << courseTitle<< endl;
cout << "Enter the course number (e.g.CS200) oe E to exit: ";
cin >> crseNum1;
return crseNum1;
}
|