Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<fstream>
- using namespace std;
- bool getdata(int value) {
- bool isntCorrect = false;
- if ((value > 10) || (value < 0)) {
- cout << "Invalid file data. Value from " << 0 << "to " << 10 << " expected";
- isntCorrect = true;
- return isntCorrect;
- }
- }
- bool checkdata(int marks [30][10]) {
- bool isntCorrect = false;
- for (int i = 0; i < 30; i++)
- for (int j = 0; j < 10; j++)
- if (!getdata(marks[i][j])) {
- isntCorrect = true;
- }
- return checkdata;
- }
- int getNumberOfBadStudents(int marks [30][10]) {
- int counter = 0;
- bool badStudents;
- for (int i = 0; i < 30; i++) {
- badStudents = false;
- for (int j = 0; j < 10; j++) {
- if ((marks[i][j] < 4) && (!badStudents)) {
- counter++;
- badStudents = true;
- }
- }
- }
- return counter;
- }
- void body() {
- int marks [30][10];
- int numberOfBadStudents;
- bool isntCorrect = false;
- ifstream fin("D:\\input.txt");
- ofstream fout("D:\\output.txt");
- for (int i = 0; i < 30; i++) {
- cout << "\n";
- for (int j = 0; j < 10; j++) {
- fin >> marks[i][j];
- cout << marks[i][j] << " ";
- }
- }
- isntCorrect = checkdata(marks);
- if (isntCorrect) {
- numberOfBadStudents = getNumberOfBadStudents(marks);
- fout << "\nNumber of bad students: " << numberOfBadStudents;
- cout << "\nNumber of bad students: " << numberOfBadStudents;
- }
- else
- cout << "File input.txt does not exist";
- }
- int main() {
- body();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement