Home > Back-end >  C primer plus 6 th sixth chapter 6.9 code programming questions how to write, it's too difficul
C primer plus 6 th sixth chapter 6.9 code programming questions how to write, it's too difficul

Time:09-26

Topic: a text, the first line is the number of donors, the second line is the first names, and the third row is the first donor contributions, then the next person name and donations, write a program to respectively to read data from the document, and then will be greater than or equal to 10000 listed in the Grand Patrons in the list, otherwise the inclusion of Patrons, if one is empty, print none! ; Successfully opened, this text will also be able to successfully read the first line number, and then can not continue reading, the result is as follows:
//
Enter the filename: donors. TXT
Grand Patrons:
None!
Patrons:
0
0
0
0
The Program ended with exit code: 0
//

The following is a code, can you tell me the great spirit of all stripes, what's the problem???????
# include & lt; iostream>
# include & lt; string>
# include & lt; Fstream>
# include & lt; vector>
# include & lt; Cstdlib>
using namespace std;
Struct donor {
String name;
Double money.
};
Int main () {
Int n;
Char filename [20].
Cout<" Enter the filename: ";
Cin. Getline (filename, 20);
Ifstream infile.
Infile. Open (filename);
if(! Infile. Is_open ())
{
Cout<" Could not open "& lt; exit(EXIT_FAILURE);
}
(infile> N). The get ();
Vector Ar (n);
for(int i=0; i{
Getline (infile, ar [I] name);
(infile> Ar [I] money). The get ();
}
Cout<" Grand Patrons: "& lt; Int m=0;
for(int i=0; iIf (ar [I] money>
=10000){
Cout+ + m;
}
If (m==0)
Cout<" None!" m=0;
Cout<" Patrons: "& lt; for(int i=0; iIf (ar [I] money<10000)
{
Cout+ + m;
}
If (m==0)
Cout<" None!" Infile. Close ();
return 0;
}

CodePudding user response:

First statement, this is my baidu, no debugging
 # include & lt; iostream> 
# include & lt; Fstream>
# include & lt; string>


Int main ()
{
using namespace std;
Struct Juan
{
String name;
Double k;
};
Int num=0, I=0;
Ifstream ifs.
The ifs. Open (" 2. TXT ");
Ifs> Num.
Const int count=num;
Juan * member=new Juan (count);
While (num -)
{
The ifs. The get ();
Getline (ifs, member [I] name);
Ifs> Member [I]. K;
i++;
}
Cout<" Grand Patrons: "& lt; Num=0;
for(i=0; iIf (member [I] k> 10000)
{
Coutnum++;
}
If (num==0)
Cout<" None "& lt; Num=0;
Cout<" Patrons: "& lt; for(i=0; iIf (member [I] k<10000)
{
num++;
Cout}
If (num==0)
Cout<" None "& lt; return 0;
}

CodePudding user response:

Not debugging, the front part whether can open the file, display your text? Why https://bbs.csdn.net/topics/396510443
 
Int n;
(infile & gt;> N). The get ();
Vector Ar (n);
For (int I=0; i{
Getline (infile, ar [I] name);
(infile & gt;> Ar [I] money). The get ();
}
Cout & lt; <"Grand Patrons:" & lt; Int m=0;
For (int I=0; iIf (ar [I] money & gt;=... )
{
Cout & lt; + + m;
}
If (m==0)
Cout & lt; <"None!" m=0;
Cout & lt; <"Patrons:" & lt; For (int I=0; iIf (ar [I] money<. )
{
Cout & lt; + + m;
}
If (m==0)
Cout & lt; <"None!" Infile. Close ();

CodePudding user response:

The pipe ends and ends here ah, is really a good chance,

CodePudding user response:

refer to the second floor the wise know already should good karma response:
no debugging, the front part whether can open the file, display your text? Why https://bbs.csdn.net/topics/396510443
 
Int n;
(infile & gt;> N). The get ();
Vector Ar (n);
For (int I=0; i{
Getline (infile, ar [I] name);
(infile & gt;> Ar [I] money). The get ();
}
Cout & lt; <"Grand Patrons:" & lt; Int m=0;
For (int I=0; iIf (ar [I] money & gt;=... )
{
Cout & lt; + + m;
}
If (m==0)
Cout & lt; <"None!" m=0;
Cout & lt; <"Patrons:" & lt; For (int I=0; iIf (ar [I] money<. )
{
Cout & lt; + + m;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related