{
return a * x * x + b * x + c;
}
:
y = 4.25
x, a b
y = 1.25
x
y = 0
5.2.5
++ , ', .
¾ ', .
5.6. .
#include <string.h>
#include < iostream >
Using namespace std;
int funp (int x) // 1.
{ return x*x; }
int funp (unsigned x) // 2.
{ return -x*x; }
char funp (char x) // 3.
{ return x+3; }
int funp (int x, char *y) // 4.
{ return x*strlen (y); }
int funp (int x, char y) // 5.
{ return x*y; }
float funp (float r) // 6.0
{ return r*r; }
float funp (double r) // 7.
{ return r+r; }
Int main ()
{
cout << funp(5) << endl; // 25
cout << funp ((unsigned)10) << endl; // 100
cout << funp ('') << endl; // d
cout << funp (4,"abc") << endl; // 12
cout << funp (4, '') << endl; // 388
cout << funp(1.2)<< endl; // 1.44
cout << funp((double) 4.5) << endl; // 9
Return 0;
}
, , .
5.3
1. ?
2. , ?
3. ?
4. ?
5. ?
6. ?
7. ?
8. ?
9. ?
10. ?
5.4
1. , 䒺 A(12), B(10), C(8) 10.
2. n - .
3. 2- .
4. , .
5. .
6. .
7. .
|
|
8. .
9. A(5,4), B(3,2), C(4,4) .
10. , , .
11. , . , .
12. .
13. . .
14. . .
15. . .
16. .
17. - ( , - - ) .
18. .
19. ³. , .
20. , .
21. .
22. .
23. .
24. .
25. , . .
6.1 ֳ
: , .
6.2
, .
- ++ (, , , ).
, . , , .
|
|
- ( ) iostream.h, iostream, :
#include <iostream>
- - - fstream, .
-, -.
- fstream, ():
void open (const char *filename, int mode, int m = flebuf:: openprompt);
filename ¾ ' , , ;
mode ¾ , , fstream ;
m ¾ , , , filebuf:: openprompt;
mode , , , " ", "|". :
ios:: app ¾ () (" ");
ios:: in ¾ (" r ");
ios:: out ¾ (" w ");
ios:: ate ¾ ;
ios:: binary ¾ ;
ios:: trunc ¾ ;
ios:: nocreate ¾ , ¾
;
ios:: noreplace ¾ ¾ , .
:
#include < fstream >
Using namespace std;
Int main ()
{
fstream fp; // ;
// myfile.dat , ;
fp. open (" a: \ cpp \ myfile.dat ", ios:: out)
// file2.dat ;
fp.open (" c: \ vp \ file2.dat ", ios:: in);
//
// ;
fp.open (" myfile ", ios:: out | ios:: in | ios:: binary);
return 0;
}
fp ' fstream ofstream. , fp = 0, . :
#include < fstream >
Using namespace std;
Main ()
{
Ofstream fp;
fp.open (" Filename ", ios:: app); //
if (!fp)
{
cout << " " << endl;
Exit (0);
} //
Else
{
//
}
}
, :
while (! fp.eof ())
{
...}
6.1 ' .
//P5_1.CPP ¾ '
#include < fstream >
Using namespace std;
Int main ()
{
Ofstream fp;
fp.open (" a: \ Myfile ", ios:: out); //
fp << " 人 .. " << endl;
fp << " .. " << endl;
fp << " .. " << endl;
|
|
fp << " .. " << endl;
fp << " .. " << endl;
fp. close (); //
}
³ , , ifstream ¾ ( ) ofstream ¾ :
ifstream in (" Namefile "); //
ofstream out (" Namefile2 "); // ,
in out ¾ .
6.2 .
// P5_2.CPP ¾ file1 file2
#include <fstream>
#include < iostream >
Using namespace std;
Void main ()
{
ifstream in (file1");
ofstream out ("file2");
char st [80];
while (! in.eof ())
{
in.getline (st, 80) // in ¾ ' ifstream
out << st << endl; // st file2
cout << st << endl; // st
}
In.close();
Out.close();
}
ifstream ofstream : ifstream in (const char *name, int mode = ios:: in,
int prot = filebuf:: penprot);
, open.
6.3 matr (2, 4) .
//P5_3.CPP ¾
#include <iostream>
#include < fstream >
Using namespace std;
Void main ()
{
int mas [4], matr [2][4];
Int i, j;
ofstream out (" filemat ");
for (i = 0; i < 2; i++)
for (j = 0; j < 4; j++)
{
cin >> mas [j];
out << mas[j]<< ;
}
Out. close();
ifstream in ("filemat );
for (i = 0; i < 2; i++)
{
for (j = 0; j < 4; j++)
in>> matr [ i ] [ j ]; //
}
In. close ();
for (i = 0; i < 2; i++) //
{
cout << endl;
for (j = 0; j < 4; j++)
cout << matr [i] [j];
}
}
6.3
1. ?
2. ?
3. ?
4. ?
5. ?
6. ?
6.4
1. , : , , .
2. , . .
3. , . , .
4. , : , , . .
5. , . .
6. , X(20). Y(4,5).
7. , : , . .
8. , . .
|
|
9. , . , .
10. , , . .
11. , . , .
12. , . , .
13. , : , , . , .
14. . ⳺?
15. , . , .
16. , . .
17. , , . .
18. , . .
19. C ++ " cin " " if ".
20. , . .
21. , . , " ".
22. ++ (' ) , ', ";".
23. , . , , .
24. .
25. .
˲ Ѳ
1. .. /++. .: 2004., 461 .
2. . C++: . - .: , 2003. 521 .
3. .. C C++. .: , 2006. 647 .
4. . ++. 1. : "", 1993. 264 .
5. . ++. 2. : "", 1993. 296 .
6. . . ++: . 5 - . - .: , 2000. - 560 .
7. .. . ++. : , 2002. 500 .
8. .., .. ++.- .: ̻, 2000 . 1024 .
6.170103 - .
: ѳ .
³ . .
, .16
ϳ. 6084 1/16
. . . 4,8. . . 4,2. .32.
120 .
.___.ֳ .
H. 61726 , . , 14.
- - H
61726 , . , 14.