:
1) abstract class A{virtual f()=0;};
*2) class A{virtual f()=0;};
3) class A{virtual f();};
2. , :
1) ;
2) ;
3) ;
*4) .
3. :
1) ;
2) , ;
*3) ;
4) .
4.
class A{public:virtual void f(){cout<<1;}};
class B:public A {public:virtual void f(){cout<<2;}};
,
B b;A &a=b; a.f();?
:
*1) 2; 2) 21; 3) 12; 4) 1; 5) .
5.
class A {public:void f(){cout<<1;}};
class B:public A{public: void f(){cout<<2;}};
,
B b; b.f();?
:
*1) 2; 2) 21; 3) 12; 4) 1.
6.
class A{public:virtual void f(){cout<<1;}};
class B:public A{public:virtual void f(){cout<<2;}};
,
B b; b.f();?
:
*1) 2; 2) 21; 3) 12; 4)1; 5).
6
. ,
C++
. ++ - . . cin, cout, cerr, clog. . iostream.h : istream, ostream, - iostream.
- fstream.h, istream ostream ifstream, ofstream fstream, . :
Ifstream in;//
Ofstream out;//
Fstream io;//-
, open() . open():
void open (char *filename,int mode,int access);
filename , ; mode (ios::in , ios::out , ios::binary , ); access: 0 , 1 , 8 . close().
- - >> << . - :
istream &get(char &ch); ostream &put(char ch);
- n :
istream &read(unsigned char *buf, int n);
|
|
ostream &write(const unsigned char *buf, int n);
. ++ . try. catch. try-catch :
try {/* try*/ }
catch(type1 arg){/* catch*/}
try catch. catch, . catch. try, throw, catch.
catch()
{/**/}
, try, , :
( ) throw( )
{/**/ }
. . , ( , ). - .
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
struct Student{
int num;
char surname[10];
int group;
int balls;
friend ostream &operator<< (ostream &stream, Student stud){
stream << " " << stud.num << " " << stud.surname << " " << stud.group
<< " " << stud.balls;
return stream;
}
friend istream &operator>> (istream &stream, Student &stud){
stream >> stud.num >> stud.surname >> stud.group >> stud.balls;
return stream;
}
};
struct node{
Student info;
node *nextl, *nextr;
node (){
info.num = info.group = info.balls=0;
nextl = nextr = 0;
}
node (Student newinfo){
info = newinfo;
nextl = nextr = 0;
}
};
template <class T, class T1> class tree{
public:
T *root;
tree() { root = 0; }
void push (T *& wer, T1 dat, int n){
if (wer == 0){
try{
wer = new T;
if(!wer) throw 1;
wer->nextl = 0; wer->nextr = 0; wer->info = dat;
}
catch (int mthrow) {cout<<No memory!<<endl;return;}
}
else if (n == 1)
if (strcmp(dat.surname,wer->info.surname) < 0) push (wer->nextl, dat, 1);
else push (wer->nextr, dat, 1);
else
if (dat.balls > wer->info.balls) push (wer->nextl, dat, 2);
else push (wer->nextr, dat, 2);
}
void insert (T1 dat, int n){
if (root == 0) root = new T(dat); else push (root, dat, n);
}
void look (ostream &stream, T *&wer){
if (wer!= 0){
look (stream, wer->nextl);
stream << " " << wer->info << endl;
look (stream, wer->nextr);
}
}
friend ostream &operator<< (ostream &stream, tree ob)
{ ob.look (stream, ob.root); return stream; }
};
void main(){
int m;
do{
cout << "1. Sort with names\n";
cout << "2. Sort with balls\n";
cout << "3. Exit\n";
cin >> m;
|
|
switch (m){
case 1: {
tree<node, Student> q;
node *n;
ifstream infile("stud.txt");
while(!infile.eof()){
Student c;
infile >> c;
q.insert(c, 1);
}
infile.close();
cout<<q;
break;
}
case 2: {
tree<node, Student> q;
node *n;
ifstream infile("stud.txt");
Student *c;
c = new Student;
int i = 1;
float s = 0;
while(!infile.eof()){
infile >> c[i];
s+=c[i].balls;
i++;
}
for (int j=1; j<=i; j++)
if (c[j].balls > s/i)
q.insert(c[j], 2);
infile.close();
cprintf(" Miide ball is %1.3f",s/i);
cout<<'\n' << q;
break;
}
case 3: {return;}
default: {cout<<"Error! Try again\n"; break;}
}
getch();
clrscr(); }
while(m!= 3);
return;}
, 13. . . . , .
I
) Student (. 1) . . 1 .
:
) Abiturient (. 1);
) Aeroflot (. 1);
) Worker (. 1);
) Train (. 1);
) Product (. 1);
) Patient (. 1);
) Bus (. 1);
) Customer (. 1);
) File (. 1);
) Word (. 1);
) House (. 1);
) Phone (. 1);
) Person (. 1).
II
) 1 . 2 ( Complex) . .
:
) Fraction (. 2);
) Vector (. 2). ;
) Matrix (. 2);
) Polynom (. 2);
) Stack (. 2);
) (. 2);
) Set (. 2);
) (. 10 . 2);
) (. 2);
) (. 2);
) (. 2).
III
, I II, , (. . 3).
1. char a[8]; cin>>a; Hello World, a?
:
1) Hello W; 2) Hello Wo; *3) Hello; 4) Hello World; 5) lo World.
2.
double x=12.4;
cout<<setw(5)<<x<<setw(3)<<setfill(*)<<<<endl;?
:
1) 12.40***; *2) 12.4***; 3) 12.4 ***; 4) 12.40; 5).124e2***.
3. int x; cin>>x; 1.2, x?
:
*1) 1; 2) 2; 3) 1.2; 3) ; 4) .
4. ?
:
1) strstream; *2) ostream; 3) ofstream; 4) istream; 5) ifstream.
5. :
#include <iostream.h>
void main (){
char A[]=ABC;
char *U=&A[2];
cout<<\n<<*U--<<*U--<<*U<<endl; }?
:
1) BAA; *2) CBA.
6. double x; cin>>x; 12-3, x?
:
1) 9.0; *2) 12.0; 3) ; 4) .
7. , , :
1) strstream; 2) ostream; 3) ofstream; 4) istream; *5) ifstream.
|
|
8. throw C,
class A {};
class B: public A {};
class C: public A {};
catch (B&b) {cout<<1;}
catch (C&c) {cout<<2;}
catch (A&a) {cout<<3;}
catch () {cout<<4;}?
:
1) 1; *2) 2; 3) 3; 4) 4; 5) 34; 6) 234.
9.
class A {
char *ptr;
public:
A () {ptr=new char [size]; Init ();}
~A () { if (ptr) delete [] ptr;}
};
, ?
:
1) , ; 2) , new; *3) , A; 4) , .
10. :
1) ; *2) ; 3) .
11. ,
class A {};
class B: public A {};
class C: public A {};
throw catch :
throw A;
catch (B&b) {cout<<1;}
catch (C&c) {cout<<2;}
catch (A&a) {cout<<3;}
catch () {cout<<4;}?
:
1) 1; 2) 2; *3) 3; 4) 4; 5) 34; 6) 234.
12. throw
*1) ;
2) Exception.
13. ,
class A {};
class B: public A {};
class C: public B {};
throw catch :
throw C;
catch (B&b) {cout<<1;}
catch (C&c) {cout<<2;}
catch (A&a) {cout<<3;}
catch () {cout<<4;}?
:
*1) 1; 2) 2; 3) 3; 4) 4; 5) 1234; 6) 234.
1. , . ++/ . . .:, 1999.
2. , . ++/ . . 3- . .:BXV-, 2002.
3. , . ++. ++/ . . 2- . .:, 2004.
4. , . ++. / . , . . .:, 2004.
5. , .. ++. - : / . . , . . . .:, 2004.
6. , .. ++/ . . , . . , . . . :, 2002.
7. , . . ++. / . . . .:, 2003.
1. . 3
2 . ................. 9
3. . .............................................................................. 19
4. . ................. 26
5. . ....................... 33
6. . , C++.......................................................................................... 44
++.
-
-
__
. .
__.__.2005. 6084/16. . .
|
|
... ____. .-... 100 . .
.
315 14.07.98.
220050, , . . ,4.
.
220030, , . , 6.