Advertisement
fahimkamal63

Untitled

Sep 27th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. struct stu{
  8.     int roll;
  9.     string name;
  10.     int marks;
  11. };
  12.  
  13. void sort_marks(stu ob[], int n){
  14.     for(int i = 0; i <n; i++){
  15.         for(int j = i + 1; j < n; j++){
  16.             if(ob[i].marks < ob[j].marks){
  17.                 struct stu temp;
  18.                 temp = ob[i];
  19.                 ob[i] = ob[j];
  20.                 ob[j] = temp;
  21.             }
  22.         }
  23.     }
  24. }
  25.  
  26. void sort_roll(stu ob[], int n){
  27.     for(int i = 0; i <n; i++){
  28.         for(int j = i + 1; j < n; j++){
  29.             if(ob[i].marks == ob[j].marks){
  30.                 struct stu temp;
  31.                 if(ob[i].roll > ob[j].roll){
  32.                     temp = ob[i];
  33.                     ob[i] = ob[j];
  34.                     ob[j] = temp;
  35.                     i--;
  36.                     break;
  37.                 }
  38.  
  39.             }
  40.         }
  41.     }
  42. }
  43.  
  44. int main(){
  45.     int t; cin >> t;
  46.  
  47.     struct stu ob[t];
  48.     for(int i = 0; i < t; i++){
  49.         int a; cin >> a;
  50.         string name; cin >> name;
  51.         int marks; cin >> marks;
  52.         ob[i].roll = a;
  53.         ob[i].name = name;
  54.         ob[i].marks = marks;
  55.     }
  56.     cout << "Roll | Name       | Marks" << endl;
  57.     cout << "-------------------------" << endl;
  58.     sort_marks(ob, t);
  59.     sort_roll(ob, t);
  60.  
  61.     for(int i = 0; i < t; i++){
  62.         cout << setw(4) << setiosflags(ios::right) << ob[i].roll << resetiosflags(ios::right) << " | ";
  63.         //cout.unsetf ( ios::right );
  64.         cout << setw(10) << setiosflags(ios::left)  << ob[i].name << " | ";
  65.         cout << setw(4) << setiosflags(ios::left) << ob[i].marks;
  66.         if(i != t-1) cout << endl;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement