3个回答
展开全部
#include<iostream>
using namespace std;
class Crecsize // 矩形面积类
{
private:
double length;//矩形长
double height;//矩形宽
public:
Crecsize(double a,double b);
double size(); //面积计算
}
Crecsize::Crecsize(double a,double b)
{
length=a;
hight=b;
}
double Crecsize::size()
{
recsize=length*hight;
return recsize;
}
void main()
{
double temp1,temp2;
cout<<"请输入矩形的长和宽:";
cin>>temp1>>temp2;
cout<<endl;
Crecsize rec(temp1,temp2);
cout<<"输入的矩形的长宽所对应的矩形的面积为:"<<rec.size<<endl;
}
using namespace std;
class Crecsize // 矩形面积类
{
private:
double length;//矩形长
double height;//矩形宽
public:
Crecsize(double a,double b);
double size(); //面积计算
}
Crecsize::Crecsize(double a,double b)
{
length=a;
hight=b;
}
double Crecsize::size()
{
recsize=length*hight;
return recsize;
}
void main()
{
double temp1,temp2;
cout<<"请输入矩形的长和宽:";
cin>>temp1>>temp2;
cout<<endl;
Crecsize rec(temp1,temp2);
cout<<"输入的矩形的长宽所对应的矩形的面积为:"<<rec.size<<endl;
}
展开全部
已级给你实现了,我在具体修正了的地方加了注释:
#include "stdafx.h"
#include "stdafx.h"
#include
#include
#include
using namespace std;
class Player{
private:
char PlayerID[20];
char PlayerName[10];
int PlayerLevel;
int Experience;
public:
Player();
~Player();
void GetPlayerInfo();
void PutPlayerinfo(Player *ptr);
int search(Player *ptr, char *ID);
void sort(Player *ptr);
};
Player::Player()//构造函数得要
{
}
Player::~Player()//析造函数也得要
{
}
void Player::GetPlayerInfo(){
int cont=0;
cout<<"\n输入玩家的ID:"<<endl;//少了个<<endl
cin>>PlayerID;
cout<<"\n输入玩家的姓名:"<<endl; //少了个<<endl
cin>>PlayerName;
PlayerLevel=rand()%100; //据题意要加个0-100的范围
Experience=cont++;
}
void Player::PutPlayerinfo(Player *ptr){
int cont=0;
while( cont<5 )
{
cout<<" \n玩家ID:"<<ptr[cont].PlayerID<<endl;
cout<<" 玩家姓名:"<<ptr[cont].PlayerName<<endl;
cout<<" 玩家等级为:"<<ptr[cont].PlayerLevel<<endl;
cout<<" 玩家经验值为:"<<ptr[cont].Experience<<endl;
cont++;
}
}
int Player::search(Player *ptr,char *ID){ //这个函数前你忘加Player::
for ( int i=0;i<5;i++ )
{
if ( !strcmp(ptr[i].PlayerID,ID) ) //两个字符串不能直接比较得用函数,关于这个函数请看MSDN
{
cout<<"你要查找的游戏玩家的ID是:"<<ptr[i].PlayerID<<endl; //据题意要输出的是所有信息
cout<<"你要查找的游戏玩家的姓名是:"<<ptr[i].PlayerName<<endl; //据题意要输出的是所有信息
cout<<"你要查找的游戏玩家的等级是:"<<ptr[i].PlayerLevel<<endl; //据题意要输出的是所有信息
cout<<"你要查找的游戏玩家经验值为:"<<ptr[i].Experience<<endl; //据题意要输出的是所有信息
break;
}
ptr++;
}
return 0;
}
void Player::sort(Player *ptr){ //这个函数前你忘加Player::
Player Temp;
int i,j;
for (i=0;i<5;i++ ) //一个标准的冒泡排序
{
for (j=i+1;j<5;j++ )
if (ptr[i].PlayerLevel<ptr[j].PlayerLevel ){ //下面是把两个记录交换位置
Temp.PlayerLevel=ptr[i].PlayerLevel;
Temp.Experience=ptr[i].Experience;
strcpy(Temp.PlayerID,ptr[i].PlayerID);
strcpy(Temp.PlayerName,ptr[i].PlayerName);
ptr[i].PlayerLevel=ptr[j].PlayerLevel;
ptr[i].Experience=ptr[j].Experience;
strcpy(ptr[i].PlayerID,ptr[j].PlayerID);
strcpy(ptr[i].PlayerName,ptr[j].PlayerName);
ptr[j].PlayerLevel=Temp.PlayerLevel;
ptr[j].Experience=Temp.Experience;
strcpy(ptr[j].PlayerID,Temp.PlayerID);
strcpy(ptr[j].PlayerName,Temp.PlayerName);
}
}
}
int main()
{
Player P[5];
int i=0;
while ( i<5 )
{
P[i].GetPlayerInfo();
i=i+1;
}
cout<<"请输入要找的玩家ID:"<<endl; //据题意是要用ID搜个人信息
char ID[20]; //这里应该是一个字符串而不是一个指针,否则就出大事了!
cin>>ID;
Player Test;
Test.search( P,ID );
Test.PutPlayerinfo( P ); //参数是指针所以不要用P[0],一定要这么定的话也要写成&P[0]
Test.sort( P );
Test.PutPlayerinfo( P );
system("PAUSE");
return 0;
}
#include "stdafx.h"
#include "stdafx.h"
#include
#include
#include
using namespace std;
class Player{
private:
char PlayerID[20];
char PlayerName[10];
int PlayerLevel;
int Experience;
public:
Player();
~Player();
void GetPlayerInfo();
void PutPlayerinfo(Player *ptr);
int search(Player *ptr, char *ID);
void sort(Player *ptr);
};
Player::Player()//构造函数得要
{
}
Player::~Player()//析造函数也得要
{
}
void Player::GetPlayerInfo(){
int cont=0;
cout<<"\n输入玩家的ID:"<<endl;//少了个<<endl
cin>>PlayerID;
cout<<"\n输入玩家的姓名:"<<endl; //少了个<<endl
cin>>PlayerName;
PlayerLevel=rand()%100; //据题意要加个0-100的范围
Experience=cont++;
}
void Player::PutPlayerinfo(Player *ptr){
int cont=0;
while( cont<5 )
{
cout<<" \n玩家ID:"<<ptr[cont].PlayerID<<endl;
cout<<" 玩家姓名:"<<ptr[cont].PlayerName<<endl;
cout<<" 玩家等级为:"<<ptr[cont].PlayerLevel<<endl;
cout<<" 玩家经验值为:"<<ptr[cont].Experience<<endl;
cont++;
}
}
int Player::search(Player *ptr,char *ID){ //这个函数前你忘加Player::
for ( int i=0;i<5;i++ )
{
if ( !strcmp(ptr[i].PlayerID,ID) ) //两个字符串不能直接比较得用函数,关于这个函数请看MSDN
{
cout<<"你要查找的游戏玩家的ID是:"<<ptr[i].PlayerID<<endl; //据题意要输出的是所有信息
cout<<"你要查找的游戏玩家的姓名是:"<<ptr[i].PlayerName<<endl; //据题意要输出的是所有信息
cout<<"你要查找的游戏玩家的等级是:"<<ptr[i].PlayerLevel<<endl; //据题意要输出的是所有信息
cout<<"你要查找的游戏玩家经验值为:"<<ptr[i].Experience<<endl; //据题意要输出的是所有信息
break;
}
ptr++;
}
return 0;
}
void Player::sort(Player *ptr){ //这个函数前你忘加Player::
Player Temp;
int i,j;
for (i=0;i<5;i++ ) //一个标准的冒泡排序
{
for (j=i+1;j<5;j++ )
if (ptr[i].PlayerLevel<ptr[j].PlayerLevel ){ //下面是把两个记录交换位置
Temp.PlayerLevel=ptr[i].PlayerLevel;
Temp.Experience=ptr[i].Experience;
strcpy(Temp.PlayerID,ptr[i].PlayerID);
strcpy(Temp.PlayerName,ptr[i].PlayerName);
ptr[i].PlayerLevel=ptr[j].PlayerLevel;
ptr[i].Experience=ptr[j].Experience;
strcpy(ptr[i].PlayerID,ptr[j].PlayerID);
strcpy(ptr[i].PlayerName,ptr[j].PlayerName);
ptr[j].PlayerLevel=Temp.PlayerLevel;
ptr[j].Experience=Temp.Experience;
strcpy(ptr[j].PlayerID,Temp.PlayerID);
strcpy(ptr[j].PlayerName,Temp.PlayerName);
}
}
}
int main()
{
Player P[5];
int i=0;
while ( i<5 )
{
P[i].GetPlayerInfo();
i=i+1;
}
cout<<"请输入要找的玩家ID:"<<endl; //据题意是要用ID搜个人信息
char ID[20]; //这里应该是一个字符串而不是一个指针,否则就出大事了!
cin>>ID;
Player Test;
Test.search( P,ID );
Test.PutPlayerinfo( P ); //参数是指针所以不要用P[0],一定要这么定的话也要写成&P[0]
Test.sort( P );
Test.PutPlayerinfo( P );
system("PAUSE");
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "iostream.h"
class size
{
public:
double x;
double y;
size();
};
size::size()
{
cout<<"Input x:";
cin>>x;
cout<<"Input y:";
cin>>y;
cout<<x*y<<endl;
}
int main()
{
size s;
return 0;
}
class size
{
public:
double x;
double y;
size();
};
size::size()
{
cout<<"Input x:";
cin>>x;
cout<<"Input y:";
cin>>y;
cout<<x*y<<endl;
}
int main()
{
size s;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询