fa.aramin

خطا در بازگشت وضعیت خروجی برنامم سی پلاس پلاس

fa.aramin ۱۳۹۸/۰۱/۲۸ زبان برنامه‌نویسی سی‌پلاس‌پلاس

سلام دوستان

وقتی که من سعی می کنم برنامه را اجرا کنم، خطا میده در خروجی! نمیفهمم برای چیه!! من تمام موارد و نوع متغیرها را بررسی کرده ام اما باز کار نمیکنه. 😕

راهنمایی میکنین؟ 🙂

تشکر

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

const int STUDENTS = 10;
const int SCORES = 5;
void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]);
void letterGrd (string letter[], int oGrade[]);
void output (string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]);
void highestGrade(int highScore, string highName, string name[], int oGrade[]);
void searchName(string name[], string search);
void report(string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]);

int main(){
 int ids[STUDENTS];
 string names[STUDENTS];
 int grades[STUDENTS][SCORES];
 int overGrade[STUDENTS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 string ltrGrade[STUDENTS];
 int highGrade=0;
 string bestGrade;
 string searchTerm;
 int avg=0;

 namesAndGrades (names, ids, grades, overGrade);
 letterGrd (ltrGrade, overGrade);
 output (names, ltrGrade, ids, grades, overGrade);
 highestGrade (highGrade, bestGrade, names, overGrade);
 searchName (names, searchTerm);
 report (names, ltrGrade, ids, grades, overGrade);

return 0;
}

void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]){
 char o;
 ifstream inFile;
 inFile.open("data121.txt");
 if ("data121.txt"){
 for(int x=0; x<STUDENTS; x++){
 inFile >> id[x]>>o;
 getline(inFile, name[x], ',');
 for(int y=0; y<SCORES;y++){
 inFile>>grade[x][y]>>o;
 oGrade[x]+=grade[x][y];
 }
 }
 }
 inFile.close();
}

void letterGrd (string letter[], int oGrade[]){
 for(int i=0;i<STUDENTS;i++){
 if (oGrade[i]>=90)
 letter[i]= "A";
 else if (oGrade[i]<90 && oGrade[i]>=80)
 letter[i]="B";
 else if (oGrade[i]<80 && oGrade[i]>=70)
 letter[i]="C";
 else if (oGrade[i]<70 && oGrade[i]>=60)
 letter[i]="D";
 else if (oGrade[i]<60)
 letter[i]="F";
 }
}

void output (string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]){
 for (int x=0; x<STUDENTS; x++){
 cout<< id[x]<<" "<<name[x]<<" ";
 for (int y=0; y<SCORES; y++){
 cout<< grade[x][y]<<" ";
 }
 cout<< oGrade[x]<<" "<<letter[x]<<endl;
 }
}

void highestGrade(int bestScore, string highName, string name[], int oGrade[]){
 for (int x=0; x<STUDENTS; x++){
 if (oGrade[x] > bestScore){
 highName = name[x];
 bestScore = oGrade[x];
 }
 }
 cout<<highName<<" "<<bestScore<<endl;
}

void searchName(string name[], string search){
 bool found;
 cout<< "Please enter the name of the student you would like to look up: ";
 getline(cin, search);
 for (int x=0; x<STUDENTS; x++){
 if (name[x]==search){
 found=true;
 break;
 }
 }
 if (found)
 cout<<"Found the record of "<<search<<endl;
 else
 cout<< "No record found"<<endl;
}

void reprot(string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]){
 ofstream outFile;
 outFile.open("report121.txt");
 for (int x=0; x<STUDENTS; x++){
 outFile<<id[x]<<" "<<name[x]<<" ";
 for(int y=0; y<SCORES; y++){
 outFile<<grade[x][y]<<" ";
 }
 outFile<<oGrade[x]<<" "<<letter[x]<<endl;
 }
 outFile.close();
}

طراحی سایت ارزان طراحی سایت شرکتی طراحی سایت فروشگاهی ثبت دامنه ارزان میزبانی وب لوازم یدکی ال90 لوازم یدکی مگان لوازم یدکی رنو طراحی سایت

خیلی ممنون

پاسخ‌ها به این تاپیک
سهراب عسکرزاده
سهراب عسکرزادهبرنامه نویس وب و ویندوز
۱۳۹۸/۰۱/۲۸

سلام.
خطای تایپی دارین تو اسم متد ریپورت، به متن خطا بیشتر دقت کنید حتما داخلش بوده.
کد درست:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

const int STUDENTS = 10;
const int SCORES = 5;
void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]);
void letterGrd (string letter[], int oGrade[]);
void output (string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]);
void highestGrade(int highScore, string highName, string name[], int oGrade[]);
void searchName(string name[], string search);
void report(string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]);


int main(){
 int ids[STUDENTS];
 string names[STUDENTS];
 int grades[STUDENTS][SCORES];
 int overGrade[STUDENTS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 string ltrGrade[STUDENTS];
 int highGrade=0;
 string bestGrade;
 string searchTerm;
 int avg=0;

 namesAndGrades (names, ids, grades, overGrade);
 letterGrd (ltrGrade, overGrade);
 output (names, ltrGrade, ids, grades, overGrade);
 highestGrade (highGrade, bestGrade, names, overGrade);
 searchName (names, searchTerm);
 report (names, ltrGrade, ids, grades, overGrade);

return 0;
}

void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]){
 char o;
 ifstream inFile;
 inFile.open("data121.txt");
 if ("data121.txt"){
 for(int x=0; x<STUDENTS; x++){
 inFile >> id[x]>>o;
 getline(inFile, name[x], ',');
 for(int y=0; y<SCORES;y++){
 inFile>>grade[x][y]>>o;
 oGrade[x]+=grade[x][y];
 }
 }
 }
 inFile.close();
}

void letterGrd (string letter[], int oGrade[]){
 for(int i=0;i<STUDENTS;i++){
 if (oGrade[i]>=90)
 letter[i]= "A";
 else if (oGrade[i]<90 && oGrade[i]>=80)
 letter[i]="B";
 else if (oGrade[i]<80 && oGrade[i]>=70)
 letter[i]="C";
 else if (oGrade[i]<70 && oGrade[i]>=60)
 letter[i]="D";
 else if (oGrade[i]<60)
 letter[i]="F";
 }
}

void output (string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]){
 for (int x=0; x<STUDENTS; x++){
 cout<< id[x]<<" "<<name[x]<<" ";
 for (int y=0; y<SCORES; y++){
 cout<< grade[x][y]<<" ";
 }
 cout<< oGrade[x]<<" "<<letter[x]<<endl;
 }
}

void highestGrade(int bestScore, string highName, string name[], int oGrade[]){
 for (int x=0; x<STUDENTS; x++){
 if (oGrade[x] > bestScore){
 highName = name[x];
 bestScore = oGrade[x];
 }
 }
 cout<<highName<<" "<<bestScore<<endl;
}

void searchName(string name[], string search){
 bool found;
 cout<< "Please enter the name of the student you would like to look up: ";
 getline(cin, search);
 for (int x=0; x<STUDENTS; x++){
 if (name[x]==search){
 found=true;
 break;
 }
 }
 if (found)
 cout<<"Found the record of "<<search<<endl;
 else
 cout<< "No record found"<<endl;
}

void report(string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]){
 ofstream outFile;
 outFile.open("report121.txt");
 for (int x=0; x<STUDENTS; x++){
 outFile<<id[x]<<" "<<name[x]<<" ";
 for(int y=0; y<SCORES; y++){
 outFile<<grade[x][y]<<" ";
 }
 outFile<<oGrade[x]<<" "<<letter[x]<<endl;
 }
 outFile.close();
}

موفق باشید.