Advertisement
nikitaxe132

Untitled

Oct 28th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. bool getdata(int value) {
  7.     bool isntCorrect = false;
  8.     if ((value > 10) || (value < 0)) {
  9.         cout << "Invalid file data. Value from " << 0 << "to " << 10 << " expected";
  10.         isntCorrect = true;
  11.         return isntCorrect;
  12.     }
  13. }
  14. bool checkdata(int marks [30][10]) {
  15.     bool isntCorrect = false;
  16.     for (int i = 0; i < 30; i++)
  17.         for (int j = 0; j < 10; j++)
  18.             if  (!getdata(marks[i][j])) {
  19.                 isntCorrect = true;
  20.             }
  21.     return checkdata;
  22. }
  23.  
  24. int getNumberOfBadStudents(int marks [30][10]) {
  25.     int counter = 0;
  26.     bool badStudents;
  27.     for (int i = 0; i < 30; i++) {
  28.         badStudents = false;
  29.         for (int j = 0; j < 10; j++) {
  30.             if ((marks[i][j] < 4) && (!badStudents)) {
  31.                 counter++;
  32.                 badStudents = true;
  33.             }
  34.         }
  35.     }
  36.     return counter;
  37. }
  38. void body() {
  39.     int marks [30][10];
  40.     int numberOfBadStudents;
  41.     bool isntCorrect = false;
  42.     ifstream fin("D:\\input.txt");
  43.     ofstream fout("D:\\output.txt");
  44.     for (int i = 0; i < 30; i++) {
  45.         cout << "\n";
  46.         for (int j = 0; j < 10; j++) {
  47.             fin >> marks[i][j];
  48.             cout << marks[i][j] << " ";
  49.         }
  50.     }
  51.     isntCorrect = checkdata(marks);
  52.     if (isntCorrect) {
  53.         numberOfBadStudents = getNumberOfBadStudents(marks);
  54.         fout << "\nNumber of bad students: " << numberOfBadStudents;
  55.         cout << "\nNumber of bad students: " << numberOfBadStudents;
  56.     }
  57.     else
  58.         cout << "File input.txt does not exist";
  59. }
  60. int main() {
  61.     body();
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement