Question: you have two files containing the marks of the written and practical exam of some students. Currently, The marks are in 100 but the final weight for the written part is 60 and for the practical part 40. you need to combine the marks and rank them based on the total marks. see the sample I/O for clarification.
Written.txt |
Practical.txt |
4 |
4 |
1505003 41 |
1505004 72 |
1505001 59 |
1505001 80 |
1505002 65 |
1505003 56 |
1505004 84 |
1505002 78 |
Rank.txt |
Rank ID Marks |
1
1505004 79.2 |
2 1505002 70.2 |
3
1505001 67.4 |
4
1505003 47.0 |
Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
ifstream input_written, input_practical;
int roll_written1[100], mark_written1[100], roll_practical1[100], mark_practical1[100];
int i=0, j=0;
double final_marks[100];
input_written.open("written.txt.txt");
input_practical.open("practical.txt.txt");
while(!input_written.eof())
{
int number=0, number1=0;
input_written>>number;
input_practical>>number1;
for(int z=0; z<number; z++)
{
int roll, mark, roll_practical, mark_practical;
input_written>>roll>>mark;
input_practical>>roll_practical>>mark_practical;
roll_written1[i] = roll;
mark_written1[i] = mark;
roll_practical1[j] = roll_practical;
mark_practical1[j] = mark_practical;
i++;
j++;
}
}
ofstream output;
output.open("rank.txt");
output<<"Rank"<<" "<<"ID"<<" "<<"Marks"<<"\n";
for(int k = 0; k<i; k++)
{
for(int l=0; l<i; l++)
{
if(roll_practical1[l] == roll_written1[k])
{
final_marks[k] = ( ((double)mark_written1[k]*60)/100 ) + ( ((double)mark_practical1[l]*40)/100 );
}
}
}
for(int n=0; n<i-1; n++)
{
for(int o=n+1; o<i; o++)
{
if(final_marks[n] < final_marks[o])
{
swap(final_marks[n], final_marks[o]);
swap(roll_written1[n], roll_written1[o]);
}
}
}
for(int p = 0; p<i; p++)
{
output<<" "<<p+1<<" "<<roll_written1[p]<<" "<<final_marks[p]<<endl;
cout<<" "<<p+1<<" "<<roll_written1[p]<<" "<<final_marks[p]<<endl;
}
output.close();
input_written.close();
input_practical.close();
}
No comments:
Post a Comment