7
#include <iostream.h>
class STUDENT{
int total;
public:
int get_score();
void display();
static void sort(STUDENT *s[3]);
STUDENT(int t){
total=t;
}
};
int STUDENT::get_score()
{
return total;
}
void STUDENT::display()
{
cout<<total<<endl;
}
void STUDENT::sort(STUDENT* s[3])
{
STUDENT * t;
for(int i=0;i<3;i++)
{
for(int j=2;j>i;j--)
{
if(s[j]->get_score() > s[j-1]->get_score())
{
t=s[j];
s[j]=s[j-1];
s[j-1]=t;
}
}
}
for(int k=0;k<3;k++)
cout<<s[k]->get_score()<<endl;
}
void main()
{
int s1,s2,s3;
cout<<"please input three score:"<<endl;
cin>>s1>>s2>>s3;
STUDENT *s[2];
s[0]=new STUDENT(s1);
s[1]=new STUDENT(s2);
s[2]=new STUDENT(s3);
cout<<"The result is:"<<endl;
STUDENT::sort(s);
}
8#include <iostream.h>
const int size=8;
class stack{
private:
char stck[size];
int tos;
public:
void push(char ch);
char pop();
stack(){
tos=0;
}
};
void stack::push(char ch)
{
if(tos==size)
{
cout<<"The stack is full now!"<<endl;
// return;
}
stck[tos++]=ch;
}
char stack::pop()
{
if(tos==0)
{
// cout<<"The stack is empty now!"<<endl;
return 0;
}
tos--;
return stck[tos];
}
void main()
{
stack t;
char c;
t.push('5');
t.push('2');
t.push('6');
t.push('7');
t.push('3');
while((c=t.pop())!=0)
{
cout<<c<<endl;
}
}
9
#include <iostream.h>
class person{
private :
char *name;
char *no;
public:
void setName(char *c)
{
name=c;
}
void setNo(char *n)
{
no=n;
}
char *getName()
{
return name;
}
char *getNo()
{
return no;
}
} ;
class student:public person{
private:
char *cla;
public:
void setClass(char *cl)
{
cla=cl;
}
char *getClass()
{
return cla;
}
};
class teacher:public person{
private:
char *dept;
public:
void setDept(char *de)
{
dept=de;
}
char *getDept()
{
return dept;
}
};
void main()
{
}
10
#include <fstream.h>
#include <iostream.h>
void doLine(istream& fin,ostream& out);
void main(int argc,char **argv)
{
if(argc!=3)
{
cout<<"command:xx.exe infilename.txt outfilename.txt"<<endl;
return;
}
ifstream fin(argv[1]);
ofstream out(argv[2]);
if(!fin)
{
cout<<"file not found."<<endl;
return;
}
char ch;
while(fin.get(ch))
{
if(ch=='/')
{
fin.get(ch);
if(!fin)
break;
if(ch=='/')
doLine(fin,out);
else
{
out.put('/');
out.put(ch);
}
}
else
out.put(ch);
}
}
void doLine(istream& fin,ostream& out)
{
char ch;
while(fin.get(ch))
if(ch=='/n')
{
out.put('/n');
return;
}
cout<<"Eof"<<endl;
}
11#include <iostream.h>
class Test{
private:
int num;
public:
void setNum(int n)
{
num=n;
}
int getNum()
{
return num;
}
Test(int i){
num=i;
}
};
Test t[9]={0,0,0,0,0,0,0,0,0};
void main()
{
int temp;
for(int j=0;j<9;j++)
{
t[j].setNum(0X7FF);
temp=t[j].getNum();
cout<<temp<<endl;
}
delete [] t;
}
#include <iostream.h>
class STUDENT{
int total;
public:
int get_score();
void display();
static void sort(STUDENT *s[3]);
STUDENT(int t){
total=t;
}
};
int STUDENT::get_score()
{
return total;
}
void STUDENT::display()
{
cout<<total<<endl;
}
void STUDENT::sort(STUDENT* s[3])
{
STUDENT * t;
for(int i=0;i<3;i++)
{
for(int j=2;j>i;j--)
{
if(s[j]->get_score() > s[j-1]->get_score())
{
t=s[j];
s[j]=s[j-1];
s[j-1]=t;
}
}
}
for(int k=0;k<3;k++)
cout<<s[k]->get_score()<<endl;
}
void main()
{
int s1,s2,s3;
cout<<"please input three score:"<<endl;
cin>>s1>>s2>>s3;
STUDENT *s[2];
s[0]=new STUDENT(s1);
s[1]=new STUDENT(s2);
s[2]=new STUDENT(s3);
cout<<"The result is:"<<endl;
STUDENT::sort(s);
}
8#include <iostream.h>
const int size=8;
class stack{
private:
char stck[size];
int tos;
public:
void push(char ch);
char pop();
stack(){
tos=0;
}
};
void stack::push(char ch)
{
if(tos==size)
{
cout<<"The stack is full now!"<<endl;
// return;
}
stck[tos++]=ch;
}
char stack::pop()
{
if(tos==0)
{
// cout<<"The stack is empty now!"<<endl;
return 0;
}
tos--;
return stck[tos];
}
void main()
{
stack t;
char c;
t.push('5');
t.push('2');
t.push('6');
t.push('7');
t.push('3');
while((c=t.pop())!=0)
{
cout<<c<<endl;
}
}
9
#include <iostream.h>
class person{
private :
char *name;
char *no;
public:
void setName(char *c)
{
name=c;
}
void setNo(char *n)
{
no=n;
}
char *getName()
{
return name;
}
char *getNo()
{
return no;
}
} ;
class student:public person{
private:
char *cla;
public:
void setClass(char *cl)
{
cla=cl;
}
char *getClass()
{
return cla;
}
};
class teacher:public person{
private:
char *dept;
public:
void setDept(char *de)
{
dept=de;
}
char *getDept()
{
return dept;
}
};
void main()
{
}
10
#include <fstream.h>
#include <iostream.h>
void doLine(istream& fin,ostream& out);
void main(int argc,char **argv)
{
if(argc!=3)
{
cout<<"command:xx.exe infilename.txt outfilename.txt"<<endl;
return;
}
ifstream fin(argv[1]);
ofstream out(argv[2]);
if(!fin)
{
cout<<"file not found."<<endl;
return;
}
char ch;
while(fin.get(ch))
{
if(ch=='/')
{
fin.get(ch);
if(!fin)
break;
if(ch=='/')
doLine(fin,out);
else
{
out.put('/');
out.put(ch);
}
}
else
out.put(ch);
}
}
void doLine(istream& fin,ostream& out)
{
char ch;
while(fin.get(ch))
if(ch=='/n')
{
out.put('/n');
return;
}
cout<<"Eof"<<endl;
}
11#include <iostream.h>
class Test{
private:
int num;
public:
void setNum(int n)
{
num=n;
}
int getNum()
{
return num;
}
Test(int i){
num=i;
}
};
Test t[9]={0,0,0,0,0,0,0,0,0};
void main()
{
int temp;
for(int j=0;j<9;j++)
{
t[j].setNum(0X7FF);
temp=t[j].getNum();
cout<<temp<<endl;
}
delete [] t;
}