1、#include<iostream>
using namespace std;
class Rectangle{
private:
float xl,yl,xr,yr;
public :
void setRectangle();
float perimeter( );
float area( );
int inRectangle(float x ,float y);
};
void Rectangle::setRectangle(){
cin>>xl>>yl>>xr>>yr;
}
float Rectangle::perimeter(){
cout<<"周长:"<<((xr-xl)+(yr-yl))*2.0<<endl;
}
float Rectangle::area(){
cout<<"面积:"<<(xr-xl)*(yr-yl)<<endl;
}
int Rectangle::inRectangle(float x,float y){
cin>>x>>y;
if(x>xl && x<xr && y>yl && y<yr)
cout<<"inRectangle"<<endl;
else cout<<"outRectangle"<<endl;
}
int main(){
Rectangle a;
float q,w;
cout<<"请输入x,y的范围:";
a.setRectangle();
a.perimeter();
a.area();
cout<<"请输入待判断点的坐标:";
a.inRectangle( q, w);
}
using namespace std;
class Rectangle{
private:
float xl,yl,xr,yr;
public :
void setRectangle();
float perimeter( );
float area( );
int inRectangle(float x ,float y);
};
void Rectangle::setRectangle(){
cin>>xl>>yl>>xr>>yr;
}
float Rectangle::perimeter(){
cout<<"周长:"<<((xr-xl)+(yr-yl))*2.0<<endl;
}
float Rectangle::area(){
cout<<"面积:"<<(xr-xl)*(yr-yl)<<endl;
}
int Rectangle::inRectangle(float x,float y){
cin>>x>>y;
if(x>xl && x<xr && y>yl && y<yr)
cout<<"inRectangle"<<endl;
else cout<<"outRectangle"<<endl;
}
int main(){
Rectangle a;
float q,w;
cout<<"请输入x,y的范围:";
a.setRectangle();
a.perimeter();
a.area();
cout<<"请输入待判断点的坐标:";
a.inRectangle( q, w);
}
2、
3、
#include <iostream>
using namespace std;
class Score
{ private:
int num,math,english,programming;
double average;
public:
void inscore( );
void showscore( );
};
void Score::inscore( )
{
cin>>num>>math>>english>>programming;
average=(math+english+programming)/3;
}
using namespace std;
class Score
{ private:
int num,math,english,programming;
double average;
public:
void inscore( );
void showscore( );
};
void Score::inscore( )
{
cin>>num>>math>>english>>programming;
average=(math+english+programming)/3;
}
void Score::showscore()
{
cout<<"num:"<<num<<" math:"<<math<<" english:"<<english<<" programming:"<<programming<<" average:"<<average<<endl;
}
{
cout<<"num:"<<num<<" math:"<<math<<" english:"<<english<<" programming:"<<programming<<" average:"<<average<<endl;
}
int main()
{ Score *s; int n,i;
cout<<"请输入学生人数:";
cin>>n;
s=new Score[n];
cout<<"请输入学生信息:"<<endl;
for (i=0; i<n; i++)
s[i].inscore(); //s[i]还可以表示成*(s+i)
cout<<"学生信息:"<<endl;
for (i=0; i<n; i++)
s[i].showscore();
return 0;
}
{ Score *s; int n,i;
cout<<"请输入学生人数:";
cin>>n;
s=new Score[n];
cout<<"请输入学生信息:"<<endl;
for (i=0; i<n; i++)
s[i].inscore(); //s[i]还可以表示成*(s+i)
cout<<"学生信息:"<<endl;
for (i=0; i<n; i++)
s[i].showscore();
return 0;
}
#include<iostream>
using namespace std;
class Time
{
public:
void setTime( int h, int m, int s);
void addTime(int s1);
void showTime( );
private:
int hour, minute, second;
};
void Time::setTime(int h, int m, int s){
hour=h;
minute=m;
second=s;
}
void Time::showTime( ){
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
void Time::addTime(int s1){
int i,t;
second+=s1;
t=second/60;
for(i=0;i<t;i++){
if(second>=60){
second=second-60;
minute++;
if(minute>=60){
minute=minute-60;
hour++;
}
}
}
}
using namespace std;
class Time
{
public:
void setTime( int h, int m, int s);
void addTime(int s1);
void showTime( );
private:
int hour, minute, second;
};
void Time::setTime(int h, int m, int s){
hour=h;
minute=m;
second=s;
}
void Time::showTime( ){
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
void Time::addTime(int s1){
int i,t;
second+=s1;
t=second/60;
for(i=0;i<t;i++){
if(second>=60){
second=second-60;
minute++;
if(minute>=60){
minute=minute-60;
hour++;
}
}
}
}
int main(){
Time t;
t.setTime(10,25,56);
t.showTime();
t.addTime(100);
t.showTime();
return 0;
}
Time t;
t.setTime(10,25,56);
t.showTime();
t.addTime(100);
t.showTime();
return 0;
}