array and vectors

You have 10 students.

1. Get each student's score (0 - 100).

2. Display each student's ID (1 - 10) and their grade.

3. Display sum of all grades and average at the end in nice table format.

4. You must use arrays to store student IDs and student grades.

5. At last, count how many students are in each grade ranges (< 50, 50s, 60s, 70s, 80s, 90s) and display the results

how to write in C++
Last edited on
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
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>

struct Student
{
	int Grade;
	int StudentID;
};

void GradeInput(Student * student);
void PrintInformation(Student * student);

int main()
{
	Student student[11] = { 0 }; // Create an array of structs. Each element of the array holds 2 ints: student grade and student ID.

	GradeInput(student); // Pass the address of the struct to our function
	PrintInformation(student); // Pass the address of the struct to our function
	std::cin.get();
}

void GradeInput(Student * student) // declare a pointer that points to our Student structure
{
	for (int i = 0; i < 10; i++)
	{
		std::cout << "Enter grade for student " << i + 1 << "." << std::endl; // i + 1 because arrays start counting at 0.
		std::cin >> student[i].Grade; // Get user input for int Grade.
		std::cout << "Enter ID for student " << i + 1 << "." << std::endl;
		std::cin >> student[i].StudentID; // Get user input for int Student ID.
	}
}

void PrintInformation(Student * student)  // declare a pointer that points to our Student structure
{
	for (int i = 0; i < 10; i++)
	{
		std::cout << "Student " << i + 1 << "'s grade: " << student[i].Grade << "." << std::endl; // Output our student ID.
		std::cout << "Student " << i + 1 << "'s ID: " << student[i].StudentID << "." << std::endl; // Output our student ID.
	}
}


I did the first two for you. Use this as a reference to help you with 3 and 5.
Last edited on
I don't know how to find range?
Topic archived. No new replies allowed.