Unclear/Confusing C++ Project?

New to C++. Taking a course in C++. Project has confusing instructions.

"A teacher wants to list all her students’ full names, considering only for the two students at the front and the end of the list that must be in alphabetical order. That meant the student at the top and at the end of the list will be set alphabetically according to their full name.

Write a C++ program that can help her with the issue. The list of names could be either read in from an external text file or entered from the keyboard, one full name at a time.

Once all the names have been read in, the program reports which name should be at the top of the list, and which name should be at the end of the list, in alphabetical order of their names. Also, the list of names must be displayed on the screen, together with the original order that their names were entered, for the teacher to check back of her record.



Assume that no two students have the same name. Using array, (or vector), is not allowed and will have no credit, absolutely.



Lastly, allow your program to run continuously as often as the user wishes (for another set of names). Before ending the program, your name as the programmer must be displayed.



Input validation: the number of students must be in the range of 5 to 45, inclusively.

Hint: Why is array not allowed? Because there is no need for sorting alphabetically all the names."

How exactly am I supposed to know what name to put at the end and the top if I can't sort all the names alphabetically?
Last edited on
You don't need to sort a sequence to find the maximum and minimum values.
nor to store all the values. you just need to look at each one once.

if I read you a list of numbers …
123. that is the smallest you have found so far, so save it as the smallest.
now I say 456, is that smaller? No? Throw it away.
now I say 11. Is that smaller? Yes? Save it as smallest.
Now I say 31415... and so on. you can do the same thing, at the same time, for a largest value to track both.
Last edited on
I'm still not understanding. @jonnin am I supposed to assign numbers to each name?
pseudocode:
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
string name 
read in the first name into name

# comment: initially, the first name read in is 
#          both the top name and the bottom name 
string top_name <- name
string bottom_name <- name 

# comment: print the first name that was read in on the screen
print name 

loop: # comment: for each subsequent name to be read

     read in the next name into name
     # comment: print each name that was read in on the screen
     print name 
     
     # comment: check if this name becomes the new top name or the bottom name
     if name is less than top_name then top_name <- name
     if name is greater than bottom_name then bottom_name <- name

end loop # comment: when there are no more names to be read

# comment: finally, after all the names have been read and printed out,
#          print the top_name and the bottom_name on the screen
print "name at the top of the list would be: " top_name 
print "name at the bottom of the list would be: " bottom_name
Last edited on
@JLBorges thank you so much for your answer! I kind of get what I'm supposed to do now, but I'm also still really lost. I don't need anyone to write the program for me, it's just that I need to understand exactly how the alphabetization is supposed to be done.
Use std::string
C++ strings allow you to directly initialize, assign, compare, and reassign with the intuitive operators, as well as printing and reading

read the tutorial: https://cal-linux.com/tutorials/strings.html

For example, for case sensitive comparison:
1
2
3
if( name < top_name ) top_name = name ; 
else if( name > bottom_name ) bottom_name = name ; 
// etc 
and no, no numbers, I was explaining the algorithm.
if you need to ignore case, upper or lower case everything to compare it will make it work.
Once all the names have been read in, the program reports which name should be at the top of the list, and which name should be at the end of the list, in alphabetical order of their names. Also, the list of names must be displayed on the screen, together with the original order that their names were entered,

I think you need some clarification on the assignment.

Are you supposed to print just just the first and last alphabetical names and a list of the names in their original order? Or are you supposed to print two lists, one with the first and last alphabetized and the other in the original order?

Does it matter which bit of output is first?

In other words, given the input:
Tom
Dick
Harry
Jane

Should the output be (first and last, followed by original list):
Dick Tom
Tom Dick Harry Jane

or (list with first and last in order, followed by original list):
Dick Harry Jane Tom
Tom Dick Harry Jane

and can the first one be instead (first one with lines reversed):
Tom Dick Harry Jane
Dick Tom

and the second be (second one with lines reversed):
Tom Dick Harry Jane
Dick Harry Jane Tom
Thanks everyone for your replies! I think I'm starting to get it a little more.

@dhayden: My prof actually gave me a sample run with a .txt file of these names:
GREGORY ADELIN
NESTOR ALEX BAUTISTA
DEVION TERREL BRANCH
ANTHONY H BUTLER
MARTIN DAVID CARO
AYRTON J CELENTINO
JOCELYN CHANG
ZHENGHAO CHEN
PIONEER CHI
AURORA REGEHR CLARK
CHRISTOPHER DANIEL DRESSER
MATTHEW ERIC DUDA
REBECCA FORSON
ARNOL GARCIA-SIERRA
TYSON GOMES
LIZETTE GOMEZ-RAMOS
TESIA RENAI GRUBBS
CALEB BENJAMIN JONES
BRENTON KINNEY
ALEXIS L LY
DANIELLE MCCUTCHEON
MANUEL DE JESUS MEDINA
JOHN ANDREW MILNE
YASMIN MOHAMMADI
MARK RYAN MUNOZ
ANNIE BICH NGAN NGUYEN
JENNIFER BICH HOAI NGUYEN
BRADLEY J PARKER
WILLIAM TUCKER PAYNE
VALERIA PHOUMINE
JOHN POLLARD JR
COURTNEY S RADFORD
VICTOR SALCEDO
JEREMY MICHAEL SALINAS
PRECIOUS TOTANES
ASHAKI AYOKA WALLACE
NICHOLAS COLBY WURSTER
CHARLES JOSEPH ZIGMUND

In the sample run, the output was all the names in the order (and number) they were entered in, like 1. GREGORY ADELIN, and so on, and then:

The name at the top: ALEXIS L LY
The name at the end: ZHENGHAO CHEN

that was all I was given.
Thanks for the extra info. It looks like the pseudo code from JLBorges will work just fine.
Thanks again everyone. I think I can finish the code myself now. I really appreciate it!
Topic archived. No new replies allowed.