Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- #include <iomanip>
- using namespace std;
- struct stu{
- int roll;
- string name;
- int marks;
- };
- void sort_marks(stu ob[], int n){
- for(int i = 0; i <n; i++){
- for(int j = i + 1; j < n; j++){
- if(ob[i].marks < ob[j].marks){
- struct stu temp;
- temp = ob[i];
- ob[i] = ob[j];
- ob[j] = temp;
- }
- }
- }
- }
- void sort_roll(stu ob[], int n){
- for(int i = 0; i <n; i++){
- for(int j = i + 1; j < n; j++){
- if(ob[i].marks == ob[j].marks){
- struct stu temp;
- if(ob[i].roll > ob[j].roll){
- temp = ob[i];
- ob[i] = ob[j];
- ob[j] = temp;
- i--;
- break;
- }
- }
- }
- }
- }
- int main(){
- int t; cin >> t;
- struct stu ob[t];
- for(int i = 0; i < t; i++){
- int a; cin >> a;
- string name; cin >> name;
- int marks; cin >> marks;
- ob[i].roll = a;
- ob[i].name = name;
- ob[i].marks = marks;
- }
- cout << "Roll | Name | Marks" << endl;
- cout << "-------------------------" << endl;
- sort_marks(ob, t);
- sort_roll(ob, t);
- for(int i = 0; i < t; i++){
- cout << setw(4) << setiosflags(ios::right) << ob[i].roll << resetiosflags(ios::right) << " | ";
- //cout.unsetf ( ios::right );
- cout << setw(10) << setiosflags(ios::left) << ob[i].name << " | ";
- cout << setw(4) << setiosflags(ios::left) << ob[i].marks;
- if(i != t-1) cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement