[HELP] Assistance with arrays needed

By all means please do not give me answers. Im looking for a skeleton of what i am to do. My class is online and i am unable to talk to the teacher face to face. As you can imagine its hard for me to learn C++ efficiently on my own. So if someone(s) can help me on the way, i would greatly appreciate it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
    A. for each of the following scenario, post the C++ code to declare an array that would
store the data:
1. the GPA of 175 college students
2. the age of 2,300 citizens
3. the number of pets found in 623 households
4. the income of the top 4,500 business people
5. the number of books in each of the 27 city libraries

B. List any possible methods that can be used to assign values to an array. Give at least two
examples of assigning values to any integer array that can store at most 5 integers.

C. Review and comment on two other classmates’ answers. Agree with their code or offer
your opinion concerning their code.
*/
Last edited on
Have you learned structs yet? Make a struct with a container for each of the parts required. Then make an array of objects with that struct type:


To add data, just loop through each index until you've reached the max index or you run out of data.
Wait, I didn't read that the 1-5 were seperate and not meant to be part of the same array. Disregard what I said.

I'm guessing you're being asked what type of containers to use. A GPA requires a small amount of decimal points so float GPA[175] should do it. Age is ussually an integer, and the number of pets sounds like you need to make an array of int pets[623] and then sum the values at the end.
So far i understand it as this. My teacher is vague on what she wants. This is intermediate c++ and we just learned about functions and moving on to arrays. So i imagine it would be pretty simple.



float studentsGPA[175]
int citizenAges[2300]
int numpets[623]
long double professionalsIncome[4500]
long int numBooks[27]
Last edited on
Part B
List any possible methods that can be used to assign values to an array. Give at least two
examples of assigning values to any integer array that can store at most 5 integers.

One possible way to assign a value to an array is to assign a literal or by a named constant.

cosnt int numDays = 5;
int days[numDays];
or
days[5];

does this exceed 5 integers? Doesnt this include 0-5 arrays makign that 6 inputs?

(I dont understand fully about assigning values to arrays.)

am i on the right track or am i butchering this assignment? Its due at 11:59pm
Last edited on
Topic archived. No new replies allowed.