-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram3_driver.cpp
More file actions
139 lines (112 loc) · 4.2 KB
/
Copy pathprogram3_driver.cpp
File metadata and controls
139 lines (112 loc) · 4.2 KB
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
#include "program3.h"
/*********************************************************************
File name: program3_driver.cpp
Author: Kripa Hayanju
Date: 10/17/2025
Purpose:
Driver for program 3 to simulate course registration.
Command Parameters:
File with course and student information.
Input:
User input
Results:
Course simulation.
Notes:
-
*********************************************************************/
int main(int argc, char *argv[])
{
// Check for command line arguments
if(argc != 2)
{
cout << "Not enough arguments" << endl;
return -1;
}
// Testing Student class
cout << "=== Testing Student Class ===" << endl;
// Default constructor
Student defaultStudent;
cout << "Default Student Info: " << defaultStudent.getStudentInfo() << endl;
// Parameterized constructor
Student student1("A12345678", "Alice Johnson");
Student student2("A87654321", "Bob Smith");
cout << "Student 1 Info: " << student1.getStudentInfo() << endl;
cout << "Student 2 Info: " << student2.getStudentInfo() << endl;
// Copy constructor
Student copiedStudent = student1;
cout << "Copied Student Info (from Student 1): " << copiedStudent.getStudentInfo() << endl;
// Testing Course class with Students
cout << "\n=== Testing Course Class ===" << endl;
// Default constructor for Course
Course course1;
cout << "Default Course Info:\n" << course1.getCourseInfo() << endl;
// Parameterized constructor for Course
Course course2("CS2308", "Data Structures", 3);
cout << "Parameterized Course Info:\n" << course2.getCourseInfo() << endl;
// Enroll students in course2
cout << "\nEnrolling Students in Course 2:" << endl;
course2.enrollStudent(student1);
course2.enrollStudent(student2);
// Enroll additional student to check capacity limit
Student student3("A11223344", "Charlie Brown");
Student student4("A99887766", "Daisy Ridley");
course2.enrollStudent(student3);
if (!course2.enrollStudent(student4))
{
cout << "Failed to enroll Daisy Ridley; max capacity reached.\n";
}
// Display students in course2
cout << "\nCurrent Students in Course 2:\n";
course2.displayStudents();
// Test increaseMaxEnrollment
cout << "\nIncreasing max enrollment by 2.\n";
course2.increaseMaxEnrollment(2);
// Attempt to enroll an additional student now that capacity has increased
course2.enrollStudent(student4);
// Display updated students in course2
cout << "\nStudents in Course 2 after increasing capacity:\n";
course2.displayStudents();
// Test copy constructor for Course
Course course3 = course2;
cout << "\nCopied Course (course3) Info and Students:\n";
cout << course3.getCourseInfo();
course3.displayStudents();
// Test assignment operator for Course
Course course4;
course4 = course2;
cout << "\nAssigned Course (course4) Info and Students:\n";
cout << course4.getCourseInfo();
course4.displayStudents();
// Set up the input file stream
ifstream fileInput;
fileInput.open(argv[1]);
if (!fileInput)
{
cerr << "Error: Could not open file." << endl;
return -1;
}
// Define maximum array sizes for testing purposes
const int MAX_COURSES = 20;
const int MAX_STUDENTS = 150;
// Create arrays to hold courses and students
Course coursesArr[MAX_COURSES];
Student studentArr[MAX_STUDENTS];
int iCIndex = 0; // Index for courses array
int iSIndex = 0; // Index for students array
// Call the function to process course information from the file
processCourseInformation(fileInput, coursesArr, studentArr, iCIndex, iSIndex);
// Close the file input stream
fileInput.close();
// Output the processed data for verification
cout << "\n=== Processed Course and Student Information from File ===\n";
for (int i = 0; i < iCIndex; i++)
{
cout << coursesArr[i].getCourseInfo();
cout << "Enrolled Students:\n";
coursesArr[i].displayStudents();
cout << "--------------------\n";
}
cout << "Total Courses Processed: " << iCIndex << endl;
cout << "Total Students Processed: " << iSIndex << endl;
return 0;
}