Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A teacher has asked all her students to line up single file according to their f

ID: 3631304 • Letter: A

Question

A teacher has asked all her students to line up single file according to their first name.
For example, in one class Amy will be at the front of the line and Yolanda will be at the end. Write a program that prompts the user to enter the number of students in the class, then loops to read in that many names. Once all the names have been read in it reports which student would be at the front of the line and which one would be at the end of the line. You may assume that no two students have the same name.

Input Validation: Do not accept a number less than 1 or grater than 25 for the number of students.

Explanation / Answer


#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{

int students;
int count;
char names[25];
char first [25];
char last [25];





cout << "Enter in the number of students in the class: ";
cin >> students;
cin.ignore(25,' ');


while (students < 1 || students > 25)
{
cout << "Enter in a number that is no less than 1 and no more than 25: ";
cin >> students;
}
for (int count = 1; count <= students; count++)
{

if (count == 1) {
strcpy(first, names);
strcpy(last, names);
}
cout << "Enter in name " << count << ": ";
cin.getline(names, 25);

if (strcmp(names,first) < 0)

{

strcpy(first, names);

}

if (strcmp(names,last) > 0)

{

strcpy(last, names);

}

}



cout << "The first student is " << first<< endl;

cout << "The last student is " << last<< endl;





system("PAUSE");
return EXIT_SUCCESS;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote