#include ﹤iostream﹥
using namespace std;
class A
{
static int x;
int y;
public:
A(int a, int b)
x=a; y=b;
}
int get( )
return x +y;
};
x=5;
int main( )
A a(1,2);
cout ﹤﹤ a. get( )﹤﹤endl;
return 0;
写一个程序,定义一个抽象类Shape,由它派生3个类:Square(正方形)、Trapezoid(梯形)和Triangle(三角形)。用虚函数分别计算几种图形面积、并求它们的和。要求用基类指针数组,使它每一个元素指向一个派生类对象。
#include ﹤iostream.h﹥
class Shape
{ public:
virtual double area( )const=0;
给出下面程序输出结果。
include "iostream. h"
void main( )
int x, y, z; x=3; y=x++; z=++x;
cout﹤﹤"x="﹤﹤x﹤﹤";y="﹤﹤y﹤﹤";z="﹤﹤z﹤﹤endl;
下面程序用来求直角三角形斜边长度。
#include ﹤iostream. h﹥
#include ﹤math.h﹥
class Line;
class Point;
{ private:
double x, y;
_________
Point(double i=0, double j=0)
{ x=i; y=j; }
Point(Point &p)
{ x=p.x; y=p.y; }
class Line
private:
Point p1, p2;
Line( Point &xp1, Point &xp2): _________ { }
double GetLength( );
double Line:: GetLength( )
double dx =p2. x-p1. x;
double dy =p2. y-p1. y;
return sqrt( dx*dx +dy*dy);
Point p1, p2(6, 8);
Line L1(p1, p2);
cout ﹤﹤L1. GetLength( )﹤﹤endl;
给如下面程序输出结果。
class Base
int Y;
Base (int y=0)
Y=y;
cout ﹤﹤"Base ("﹤﹤y ﹤﹤")\n";
~Base( )
cout ﹤﹤"~Base( )\n";
void print( )
cout ﹤﹤Y﹤﹤" ";
class Derived: public Base
int Z;
Derived (int y, int z): Base(y)
Z=z;
cout﹤﹤"Derived ("﹤﹤y﹤﹤","﹤﹤z﹤﹤"\n";
~Derived( )
cout﹤﹤"~Derived( )\n";
Base:: print( );
cout ﹤﹤Z﹤﹤endl;
Derived d(10, 20);
d. print( );
编一个函数to_ lower( ),实现将字符串中的大写字母转换成相应小写字母。主函数输入数据并输出结果。
#include "stdafx. h"
_________;
void main(void)
void to_lower (char a[ ]);
char str[10];
cin﹥﹥str;
to_lower(str);
cout﹤﹤str﹤﹤endl;
void to_ lower(char a[ ])
for(int i=0; i﹤10&&a[i]!='0'; i++)
if( _________ )
a[i]+=32;
任意输入10个同学的成绩,计算其平均成绩。要求用函数average( )计算平均成绩,主函数输入数据并输出结果。
void main( void)
float average( float a[ ]);
float score[10];
for( _________ )
cin﹥ score[i];
cout﹤﹤"average: "﹤﹤ average( score)﹤﹤ endl;
float average(float a[ ])
float sum=0;
for( int i=0; i ﹤10; i++)
return (sum/10);
打印以下图案: #include "stdafx. h" #include ﹤iostream﹥ using namespace std; void main( void) { int j, n; for( _________ ) //i控制行号 { for(j=1;j﹤i;j++) //j控制空格 cout ﹤﹤' '; for( _________ ) //n控制星号 cout ﹤﹤"*"; cout ﹤﹤ endl; } }
用简单选择法对10个数排序,使其从小到大排列。
int main( void)
int t;
int num[ 10], t, j;
cin ﹥﹥num[i];
for(i=0;i﹤9;i++)
for(j=i+1;j﹤10;j++)
if(num[i]﹥ num[j])
t=num[i];
num[i]=num[j];
for(i=0;i﹤10;i++)
cout ﹤﹤num[i]﹤﹤" ";
class base{
int a, b;
pubic:
void setzero( )
x=0; y=0;
void show( )
cout ﹤﹤x﹤﹤" "﹤﹤y﹤﹤endl;
base b;
b. setzero 0, 0);
热门试卷
经济师初级(经济基础知识)模拟试卷5
经济师初级经济基础知识(商品经济的基
经济师(初级)工商管理专业知识与实务
初级经济师试题及答案3(公路运输)
经济师初级人力资源管理专业知识与实务
初级经济师《工商专业》全真模拟试卷(
初级经济师《经济基础知识》考前突破试
订单号:
遇到问题请联系在线客服