|
- #include<iostream>
- #include<fstream>
- using namespace std;
- void test1(const char an1[], bool & bo, ofstream & outdata);
- void test2(const char an1[],bool & bo, ofstream & outdata);
- void outscore(char an[],char an1[],bool bo, ofstream & outdata);
- int main()
- {
- ifstream indata;
- ofstream outdata;
- indata.open("exams.txt");
- outdata.open("scores.txt");
- while(indata)
- {
- bool bo1=true;
- char id[20]; // Caution
- char answer[22];
- indata.getline(answer,22,'\n');
- indata>>id;
- char answer1[30];
- indata.getline(answer,30,'\n');
- test1(answer1,bo1, outdata); // Caution
- test2(answer1,bo1, outdata); // Caution
- outscore(answer,answer1,bo1, outdata); // Caution
- outdata<<endl;
- }
- return 0;
- }
- void test1(const char an1[], bool & bo, ofstream & outdata)
- {
- int i,count=0;
- for(i=0;i<30;i++)
- while(an1[i]!='\0')
- count++;
- if(count<20)
- {
- outdata<<"Too few answers ";
- bo=false;
- }
- if(count>20)
- {
- outdata<<"Too many answers ";
- bo=false;
- }
- }
- void test2(const char an1[],bool & bo, ofstream & outdata)
- {
- int i;
- for(i=0;i<30;i++)
- while(an1[i]!='\0')
- while(!(an1[i]>=97&&an1[i]))
- {
- outdata<<"Invalid answers ";
- bo=false;
- }
- }
- void outscore(char an[],char an1[],bool bo, ofstream & outdata)
- {
- int i,count;
- if(bo)
- {
- for(i=0;i<20;i++)
- {
- if(an1[i]==an[i]) // Caution
- count++;
- }
- outdata<<count;
- }
- }
复制代码 |
|