| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 312 人关注过本帖
标题:[求助]C++的几个基本习题
只看楼主 加入收藏
cocoll
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-10-26
收藏
 问题点数:0 回复次数:2 
[求助]C++的几个基本习题

分析程序得结果:
1.#include<iostream.h>
class sample
{
int x;
public:
viod setx(int i){x=i;}
int putx(){return x;}
};
void mani()
{ sample*p; sample A[3]; A[0].setx(5); A[1].setx(6); A[2].setx(7); p=&A[0];
for(int j=0;j<3;j++)
cout<<p++ → putx()<<" ";
cout<<end1;
}


2.#include<iostream.h>
class Location
{
public:
Location (int xx=0, int yy=0){X=xx; Y=yy;}
Location (Location & p);
~Location(){cout<<X<<","<<Y<<"Object destroyed".<<end1;}
int GetX(){return X;}
int GetY(){return Y;}
private: int X,Y;
};
location::location(location&p)
{X=p.x;Y=p.y;cout<<"copy_constructor called."<<endl;}
void f(location p){cout<<"Function:"<<p.GetX()<<","<<p.GetY()<<endl;}
void main()
{LOcation A(1,2);f(A);}
以上程序的执行结果是————。
编程题
1。定义一个SHAPE抽象类,在此基础上派生出Circle(圆形)和Square(矩形)类,二者都有GetArea()函数计算对象的面积,GetPerim()函数计算对象的 周长。
2。使用重载函数编程序分别把俩个数.三个数和四个数从大到小排列。
初学者啦,望各位写结果的时候,帮我分析一下程序,

搜索更多相关主题的帖子: 习题 
2007-10-26 12:03
longfeng867
Rank: 1
来 自:重庆
等 级:新手上路
威 望:1
帖 子:182
专家分:0
注 册:2007-5-20
收藏
得分:0 
明确告诉你  上面的程序没有办运行~~                                                                                

在这个连处女膜都可以伪造的世界里,还有什么值得我相信!
2007-10-26 14:05
longfeng867
Rank: 1
来 自:重庆
等 级:新手上路
威 望:1
帖 子:182
专家分:0
注 册:2007-5-20
收藏
得分:0 
#include<iostream.h>
class sample
{
int x;
public:
void setx(int i)
{
x=i;
}
int putx()
{
return x;
}
};
void main()
{
sample*p;
sample A[4];
A[0].setx(5);
A[1].setx(6);
A[2].setx(7);
A[3].setx(8);
p=&A[0];
for(int j=0;j<4;j++,p++)
cout<<p->putx()<<" ";
cout<<endl;
}
============================================================================================================
#include<iostream.h>
class Location
{
public:
Location(int xx=0,int yy=0)
{
X=xx;
Y=yy;
}
Location(Location & p);
~Location()
{
cout<<X<<","<<Y<<"Object destroyed"<<endl;
}
int GetX()
{
return X;
}
int GetY()
{
return Y;
}
private:
int X,Y;
};
Location::Location(Location &p)
{
X=p.X;
Y=p.Y;
cout<<"copy_constructor called."<<endl;
}
void f(Location p)
{
cout<<"Function:"<<p.GetX()<<","<<p.GetY()<<endl;
}
void main()
{
Location A(1,2);
f(A);
}

在这个连处女膜都可以伪造的世界里,还有什么值得我相信!
2007-10-26 14:06
快速回复:[求助]C++的几个基本习题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015251 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved