-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion2.cpp
105 lines (92 loc) · 2.94 KB
/
Question2.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* 2.WAP to input name, roll number and marks in 5 subjects for n number of students. Write
functions to:-
a. Find total marks and percentage of all n students.
b. Display details of a student with a given roll number.
c. Display the details for all the students having percentage in a given range.
d. Sort the array in ascending order of marks.
*/
#include <iostream>
using namespace std;
int main()
{
int n,s;
cout << "Enter number of students : ";
cin >> n;
string name[n+1];
int roll[n+1];
int marks[n+1][5];
int total[n+1]={};
float percent[n+1];
for(int i=0;i<n;i++)
{
cout << "Enter Name, roll number and 5 marks of student " << i+1 << " :-" << endl;
cin >> name[i] >> roll[i];
for(int ii=0;ii<5;ii++)
{
cin >> marks[i][ii];
total[i] = total[i]+ marks[i][ii];
}
percent[i]=total[i]*2;
}
cout << "Percentage :- " << endl;
for(int i=0;i<n;i++)
cout << "Student " << i+1 << " : " << percent[i] << endl;
cout << "Enter a roll number to display details : ";
cin >> s;
for(int j=0;j<n;j++)
if(s==roll[j])
{
cout << "\n\nDetails :- \n\nName : " << name[j] << "\nRoll Number : " << roll[j] << endl;
for(int i=0;i<5;i++)
cout << "Marks " << i+1 << " : " << marks[j][i] << endl;
break;
}
int range1,range2;
cout << "Enter the starting and ending range of percentage :- ";
cin >> range1 >> range2;
for(int i=0;i<n;i++)
{
if(percent[i]>=range1 && percent[i]<=range2)
{
cout << "\n\nDetails :- \n\nName : " << name[i] << "\nRoll Number : " << roll[i] << endl;
for(int ii=0;ii<5;ii++)
cout << "Marks " << ii+1 << " : " << marks[i][ii] << endl;
}
}
cout << "\n\nAfter Sorting :-- " << endl;
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(total[i]>total[j])
{
name[n] = name[i];
name[i] = name[j];
name[j] = name[n];
roll[n] = roll[i];
roll[i] = roll[j];
roll[j] = roll[n];
for(int ii=0;ii<5;ii++)
{
marks[n][ii] = marks[i][ii];
marks[i][ii] = marks[j][ii];
marks[j][ii] = marks[n][ii];
}
total[n] = total[i];
total[i] = total[j];
total[j] = total[n];
percent[n] = percent[i];
percent[i] = percent[j];
percent[j] = percent[n];
}
}
}
cout << "\n\nDetails :-\n" << endl;
for(int i=0;i<n;i++)
{
cout << "\n\nName : " << name[i] << "\nRoll Number : " << roll[i] << endl;
for(int ii=0;ii<5;ii++)
cout << "Marks " << ii+1 << " : " << marks[i][ii] << endl;
}
return 0;
}