Christos
  • Christos
C++, I am trying to finish this problem 2) Write a program and declare an array called “Exam” with 100 integers. Hence, ask a lecturer to enter the number of students in a class along with each student’s mark that should be stored in the array (use a variable n to know the number of students). The program should then calculate and display: a) the average (float) and the highest and lowest marks of the class, b) the number of grades A, B, C, D and F, according to the following table. So that's my code so far.http://pastebin.com/E62wvaiW What am I doing wrong and the array won't show up ?? Please help ?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
inkyvoyd
  • inkyvoyd
your cout << exams[100] << endl; is outside the while loop
Christos
  • Christos
Can you please copy and paste your code here? I don't think that's the case.
Christos
  • Christos
@inkyvoyd

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

inkyvoyd
  • inkyvoyd
also, you declared exam of type char - your directions ask for type int?
Christos
  • Christos
Yea true that. I just have no clue how to display "A" "B" "C" "D" "F" in the array with another way.
inkyvoyd
  • inkyvoyd
just use if statements to display A B C D and F if the grades range - don't store them as ABCDF
rsmith6559
  • rsmith6559
inkyvoyd is right. You declared exams to be 100 characters. They're indexed 0 - 99. cout << exams[100] << endl; says to print the 101st element of exams, which is undefined.
inkyvoyd
  • inkyvoyd
you should store the grades inside the int exam[100] and you need rewrite your code so the array is part of a while loop, seeing as you don't want to print a single element. basically I would do this: Write a chunk of code that handles input Write a chunk of code that counts the number of A's, B's, C's, D's, and F's in the array, and store each as a separate variable Write a chunk of code that outputs this information as a table.
Christos
  • Christos
"Write a chunk of code that outputs this information as a table." How do I do that?
inkyvoyd
  • inkyvoyd
you have loops in each part of these.
inkyvoyd
  • inkyvoyd
I don't know what format the table is supposed to be seeing as you didn't give the example. I won't be able to help you there until you edit that in.
Christos
  • Christos
its this http://screencast.com/t/ZvST8aI5oA
inkyvoyd
  • inkyvoyd
ugh, you know what, I'll just write some psuedo code to give you an idea of how I would do it.
Christos
  • Christos
thanks man
inkyvoyd
  • inkyvoyd
http://pastebin.com/V33TePMZ don't even try to compile it, read it and use it as an example maybe
e.mccormick
  • e.mccormick
Global variables. Bad, bad things.
e.mccormick
  • e.mccormick
The problem with that example is that while it is workable, it defeats the purpose of the lesson. Christos has just started working with arrays, so the purpose it to force the student to use an array... no matter how useless the array is! That is why that loop should be broken into two loops. One to load the array and one to evaluate the array.
inkyvoyd
  • inkyvoyd
honestly, I'm just a kid with a very limited background in programming (I don't even know object orientated lol) - my code is probably runnable, but I don't expect it to have a programmer's elegance
e.mccormick
  • e.mccormick
@inkyvoyd It really is not an issue of how good a coder you are, elegance, and so on. It comes down to reading the question. "Write a program and declare an array called “Exam” with 100 integers." OK, so int Exam[100] must be in there. "Hence, ask a lecturer to enter the number of students in a class along with each student’s mark that should be stored in the array (use a variable n to know the number of students)." You are supposed to take input for an int n as the number of students. You are supposed to take in the percentage grade for all the students. Now, there is a key part right after this, "The program should then calculate and display:" You are NOT supposed to do any calculations while taking in the data. You must do it after. Therefore you must have two loops or you are not following the instructions. " a) the average (float) and the highest and lowest marks of the class," That is straightforward, find the average as a float and the highest and lowest, which would be ints. "b) the number of grades A, B, C, D and F, according to the following table." and how many of each type of mark needs to be counted up. So what is the real goal of all this? There are simple enough instructions. If I were to do things elegantly, I would do running calculations as the input is happening. That is easy because the computer operates so much faster than people. However, that is not what the question wants. Elegance goes out the window and you are required to take in a set of data separate from doing anything to it. Now, this does have some real world prescience. What if you have 50 people entering thousands of pieces of data and after they are all done you finally get to evaluate the data? This type of program is generally used to introduce a simple concept like that. Well, Christos said, in a different post, that she was just starting out with arrays. Therefore, the purpose of this task is to force the learner into iterating through an array. And because the processing is separate from the input: iterate the array twice! No elegance, just creation and use of an integer array as part of a learning process.
e.mccormick
  • e.mccormick
It has been a couple weeks since you started asking about this... so here is what I did some time back: http://dpaste.com/hold/1365204/ It is not 100% correct. I left the number of students as students, and not n. It started as your code and then I started reworking it into the answer required. I was hoping you would get to this point without seeing an answer...
e.mccormick
  • e.mccormick
And I don't know why it indented it oddly. It looked much nicer in my compiler!
e.mccormick
  • e.mccormick
Ah, tabs and spaces. Went to just spaces: http://dpaste.com/hold/1371090/ Much easier to read there... and I changed Students to n.

Looking for something else?

Not the answer you are looking for? Search for more explanations.