2017两会乡村医生编制:(求助,急!)有关C++的问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 06:01:58
C++没学好,请教各位大侠,麻烦帮我给出下列任意一题的源代码(尽量不要出错)
1、用C++实现复数类型
2、用类实现堆栈
3、用类实现链队列
4、用C++实现分数类型(声明分数变量,输入输出,实现各种加减法,验证它)

#include<iostream>
#include<vector>
using namespace std;
class Stack
{
public:
Stack() {init();}
void init(void) {top=-1;}
bool isempty(void) {return top<0;}
bool isfull(void) {return top>=9;}
void push ( int n )
{
if( !isfull() )
array[++top]=n;
else
cerr<<"stack is full"<<endl;
}
int pop( void )
{
if( !isempty() )
return array[top--];
else
cerr<<"stack is empty"<<endl;
}
int dump( void )
{
int i = top;
while(i>=0)
{
cout << array[ i-- ]<<" ";
}
return 0;
}
private:
int top;
int array [ 10 ];
};

建议看一看数据结构(C++实现的),一切OK!!

首先要把C++学好才行哦!!