#include <iostream>
using namespace std;
class Stu
{
public:
Stu(){}
~Stu(){}
Stu(string n,int a,int s):name(n),age(a),score(s){}
virtual void show()
{
cout<<"name:"<<name<<" age:"<<age<<" score:"<<score<<endl;
}
private:
string name;
int age;
int score;
};
class Par
{
public:
Par(){}
~Par(){}
Par(string a,string o):activity(a),organization(o){}
virtual void show()
{
cout<<"活动:"<<activity<<" 组织:"<<organization<<endl;
}
private:
string activity; //活动
string organization; //组织
};
class ganbu:public Stu,public Par
{
public:
ganbu(){}
~ganbu(){}
ganbu(string n,int a,int s,string ac,string o,string j):Stu(n,a,s),Par(ac,o),jop(j){}
void show()
{
Stu::show();
Par::show();
cout<<"职位:"<<jop<<endl;
}
private:
string jop;
};
int main()
{
// Par p1("自由","党");
// Stu s1("张三",18,99);
ganbu g1("张三",18,99,"自由","党","团员");
g1.show();
// s1.show();
// p1.show();
return 0;
}
#include <iostream>
#define MAX 5
using namespace std;
class Queue
{
private:
int data[MAX];
int front; //对头
int tail; //队尾
public:
void init(int front,int tail)
{
this->front = front;
this->tail = tail;
cout<<"***初始化成功***"<<endl;
}
bool empty()
{
return front==tail?true:false;
}
bool full()
{
return (tail+1)%MAX==front?true:false;
}
int size()
{
int a = (tail+MAX-front)%MAX;
return a*sizeof(data[0]);
}
void push(int e)
{
if(full())
{
cout<<"***队满,失败***"<<endl;
return;
}
data[tail] = e;
tail = (tail+1)%MAX;
cout<<"***入队成功***"<<endl;
}
void pop()
{
if(empty())
{
cout<<"***队空,失败***"<<endl;
return;
}
cout<<"***出队成功:"<<data[front]<<"***"<<endl;
front = (front+1)%MAX;
}
void show()
{
if(empty())
{
cout<<"***队空,失败***"<<endl;
return;
}
for(int i=front;i!=tail;i=(i+1)%MAX)
{
cout<<" "<<data[i]<<" ";
}
cout<<endl;
cout<<"***遍历成功***"<<endl;
}
};
int main()
{
int a = 0;
int c;
int b;
Queue q1;
while(1)
{
cout<<"1:初始化队列"<<endl;
cout<<"2:入队"<<endl;
cout<<"3:出队"<<endl;
cout<<"4:遍历队列"<<endl;
cout<<"5:查看队列大小"<<endl;
cout<<"0:退出"<<endl;
cin>>c;
switch(c)
{
case 1:q1.init(0,0);break;
case 2:
cout<<"请输入要入队的元素:";
cin>>b;
q1.push(b);break;
case 3:q1.pop();break;
case 4:q1.show();break;
case 5:
a = 0;
a = q1.size();
cout<<"队列大小:"<<a<<endl;break;
case 0:
cout<<"***已退出***"<<endl;
return 0;
}
}
cout << "Hello World!" << endl;
return 0;
}