用C++帮我编写一个正方形谢谢

显示出图形为正方形即可

可以编译通过了.自己试试
---------1----------
#include <iostream.h>
class rectangl
{
private:
double high;
double with;
public:

void GetValue(double w ,double h ){ with =w;high=h;cout<<"长方形";}
void GetValue(double h){cout<<"正方形";} //重用函数;
void Publish(){ cout<<"宽: "<<high<<"\t高: "<<with<<endl; }

void Test1p(double t){

cout<<"测试重用函数的可用性1:\n"
<<"测试只有一个变量的情况 ** void GetValue(double h){cin>>h;} **\n"
<<"测试时只显示一个数值表示函数完成成功:\n"
<<"测试开始:"<<endl;
cout<<t<<endl;
}
void Test1p(double t,double w){

cout<<"测试重用函数的可用性2:\n"
<<"测试只有两个变量的情况 ** void GetValue(double h,double w){cin>>h>>w;} **\n"
<<"测试时显示两个个数值表示函数完成成功:\n"
<<"测试开始:"<<endl;
cout<<t<<'\t'<<w<<endl;
}

};

void main(){
rectangl m2s;

m2s.Test1p(2,5);
m2s.GetValue(20,50);

m2s.Test1p(2);
m2s.GetValue(20);
m2s.Publish();

}

------------------2----------------
#include <iostream.h>
class counting
{
public:
float square(float,float);
counting(float,float,float);
private:
float lenth;
float width;
float high;

};
counting::counting(float x,float y,float z){ //结构函数;

lenth=x;width=y;high=z;
}
float counting::square (float x,float y){
x=2*x*y;return x;}
void main()
{
float x,y,z,s1,s2,s3;
cin>>x>>y>>z;
counting paper(x,y,z);
s1=paper.square (x,y);
s2=paper.square (z,y);
s3=paper.square (x,z);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-08-31
#include "iostream.h"
main()
{
int nLong = 0;
cout << "请输入正方形的长度:"<<endl;;
cin >> nLong ;
for(int nI = 0 ; nI < nLong ; nI ++)
{
for(int nJ = 0 ; nJ < nLong ; nJ ++)
{
cout << "* ";
}
cout << '\n';
}
}

不知道是不是你想要的
第2个回答  2013-08-31
#include <iostream>
using namespace std;
void main(void)
{
int lenSide;//正方行边长
cin>>lenSide;
int i=0;

for(i;i<lenSide;i++)
{
for(j;j<lenSide;j++)
{
cout<<"* "; //显示结果为一由*组成的正方形 ,在此可以修改显示
}
cout<<endl;
}
}
相似回答