-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentList.cpp
executable file
·108 lines (79 loc) · 2.37 KB
/
StudentList.cpp
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
// This program determines the placement of the two students in the front and back of the line by alphebetical order.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
ofstream outFile;
ifstream inFile;
outFile.open("Student.txt");
inFile.open("Student.txt");
int numStudents = 0;
string studentName, firstStudent, lastStudent;
char again = 'Y';
while (again == 'y' || again == 'Y')
{
cout << "This program determines the placement of the two students" << endl << "(in a classroom sized from 5 to 30 students) in the front and back" << endl << "of a single file line based on the alphebetical order of their first names." << endl;
cout << endl;
cout << "Please enter number of students in the class:" << endl;
cin >> numStudents;
cout << endl;
while (numStudents < 5 || numStudents > 30)
{
cin.clear();
cin.ignore(100, '\n');
cout << "ERROR!!! INVALID ENTRY!" << endl << "The number of students in the class must range from 5 to 30 total." << endl << endl << "Please enter a number between 5 and 30:" << endl;
cin >> numStudents;
cout << endl;
}
for (int i = 1; i <= numStudents; i++)
{
cout << "Please enter name of student #" << i << endl;
cin >> studentName;
cout << endl;
if (i == 1)
{
firstStudent = studentName;
lastStudent = studentName;
}
else
{
if (studentName < firstStudent)
{
firstStudent = studentName;
}
else if (studentName > lastStudent)
{
lastStudent = studentName;
}
}
}
cout << endl;
cout << " The student who is first in line is " << firstStudent << "." << endl;
cout << endl;
cout << " The student who is last in line is " << lastStudent << "." << endl;
cout << endl;
getline(cin, studentName, '\n');
getline(inFile, studentName, '\n');
cout << endl;
cout << "Would you like the rerun this program (y/n)? ";
cin >> again;
cout << endl;
cout << endl;
}
if (!(again == 'y' || again == 'Y'))
{
cout << endl;
cout << "Programmed by: Pedro Damian Sanchez Jr" << endl;
cout << endl;
cout << "Please press the <ENTER> key to exit and have a good day.";
}
cout << endl;
fflush(stdin);
cin.get();
return 0;
}