Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5.  
  6. struct Student {
  7. int kcstID;
  8. int quiz1;
  9. int quiz2;
  10. int quiz3;
  11. float average;
  12. };
  13.  
  14. int main() {
  15.  
  16. // Write Code to open Binary File
  17. ifstream exam ("student.dat" , ios::in | ios::binary);
  18. const int n=5 ;
  19. if(!exam) {
  20. cout << "Cannot open file" << endl;
  21. return 1;
  22. }
  23. Student stu[n];
  24. cout << "\n\t\t Kuwait Colleg of Science and Tecnology , Doha Kuwait "<<endl;
  25. cout <<"---------------------------------------------------------------------------- -";
  26.  
  27. for ( int i = 0 ; i < n ; i++){
  28. exam.read((char *)&stu[i], sizeof(Student));
  29. if (stu[i].quiz1 <= stu[i].quiz2 && stu[i].quiz1 <= stu[i].quiz3){
  30. stu[i].quiz1 = 0;
  31. }
  32. if (stu[i].quiz2 <= stu[i].quiz1 && stu[i].quiz2 <= stu[i].quiz3){
  33. stu[i].quiz2 = 0;
  34. }
  35. if (stu[i].quiz3 <= stu[i].quiz1 && stu[i].quiz3 <= stu[i].quiz2){
  36. stu[i].quiz3 = 0;
  37. }
  38. cout << "\n" << stu[i].kcstID << "\t" << stu[i].quiz1 << "\t" << stu[i].quiz2 << "\t" << stu[i].quiz3 << "\t" << stu[i].quiz1 + stu[i].quiz2 + stu[i].quiz3;
  39. }
  40.  
  41.  
  42. exam.close();
  43.  
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement