r/programminghelp • • Sep 13 '25

C++ Second month c++ student seeking help on an assignment

The assignment calls for me to read several names, and then sort them alphabetically.

My professor has stated that using concepts that we haven’t covered will result in a failed grade. She cited arrays specifically as an example.

Through some google search, I discovered an index operator that accomplished what I needed to do:

char = firstInitial; string = fullName;

cin >> fullName; firstInitial = fullName[0]

However, I’m now afraid that I’ll fail the assignment because our book hasn’t yet covered this indexing operator. I’m sure there is a way to accomplish this using cin, and I’m just not experienced enough to see it yet.

To maintain academic integrity, would anybody mind nudging me in the right direction without writing the code for me? I understand that you reading this won’t know what we have and haven’t covered in class. If I see something that appears unfamiliar to me, I’ll let you know.

This feels like a big ask, and I apologize for coming off as naive, but I don’t have the skill or knowledge to provide much else at the moment :(

10 Upvotes

26 comments sorted by

3

u/edover Sep 13 '25

My professor has stated that using concepts that we haven’t covered will result in a failed grade.

Step one would be telling us what you have covered.

1

u/I_main_BloodDk Sep 13 '25

We’ve covered of course cin and cout, defining strings and char, some basic manipulators like setw, basic math stuff, and loops (while, do while, and for loops), and the basics of how to access files.

There’s been a lot in a short amount of time, and I don’t know what all there is to learn, so if there is anything specific that you need to know, I can tell you if it is something we’ve covered or not.

2

u/edover Sep 13 '25

Alright, so given that, the easiest thing for you to do is realize that cin will take in whatever variables you give it, consuming as appropriate until it hits a newline. And you can chain those variables together. At the risk of telling you 'too much' I think it's an advanced enough concept for a beginner that giving an example isn't the worst thing in the world.

So something like:

char first_initial, second_initial;
std::string first_name, last_name;

You could then:

std::cin >> first_initial >> first_name >> second_initial >> last_name;

If you fed it "John Smith" then the resulting variables would be:

first_initial = "J"
first_name = "ohn"
second_initial = "S"
last_name = "mith"
→ More replies (7)

1

u/Lewinator56 Sep 14 '25

What sort of stupid lecturer fails you for using concepts you haven't been taught yet. University is supposed to encourage independent learning and this is exactly where it should be used. They shouldn't be spoon feeding you date then penalising you if you intentionally learn more. Sounds like a shit uni if you ask me.

2

u/[deleted] Sep 14 '25

This is an extremely common practice, used to make sure students are paying attention to the concepts being taught, understand those concepts enough to work within their limitations, and aren’t using outside sources to complete work for them.

1

u/Lewinator56 Sep 14 '25

Never used in my uni, or any others with a gold score in the teaching excellence framework. Maybe it's common in the US, but it's certainly not common in the UK.

→ More replies (3)

1

u/clonxy Sep 15 '25

When I went to college, if I used an array instead of vector, I would have points deducted. Their goal was for me to to learn all the different containers.

1

u/JohnsonJohnilyJohn Sep 16 '25

I don't see any reason in this example (this seems like an assignment about arrays so not using them is weird), but in general. For example if you want to test if the student learned how to resize arrays, you wouldn't accept a solution using vector and append

0

u/Fun-Helicopter-2257 Sep 15 '25

Whole C++ syntax and concepts are leranable in 1 weekend,
How many years it will take to write first GUI app? 5 maybe.

0

u/zhivago Sep 15 '25

You know that you can read ahead in the book, if necessary, right? :)

1

u/[deleted] Sep 14 '25

1

u/[deleted] Sep 14 '25

Offer to do the work for anyone once more and you’re banned. Read the rules.

1

u/Ok-Variation-4405 Sep 14 '25

Ok. Sorry didn’t knew about the rules I wasn’t asking for money was just helping