0143895吴彬第一次c++作业

7. #include <iostream>
using namespace std;
int main()
{
 int max(int a,int b,int c=0);
 int a,b,c;
 cin>>a>>b>>c;
 cout<<"max(a,b,c)="<<a<<endl;
 cout<<"max=(a,b)="<<a<<endl;
 return 0;
}
int max(int a,int b,int c)
{
  if(a<b) a=b;
  if(a<c) a=c;
  return a;
}
 
8.#include <iostream>
using namespace std;
int main()
{
 void swap(int &,int &);
 int a,b;
 cin>>a>>b;
 if(a<b)
 swap(a,b);
 cout<<a<<” ”<<b<<endl;
 return 0;
}
void swap(int &a1,int &b1)
{
 int c;
 c=a1;
 a1=b1;
 }
 
9.#include <iostream>
using namespace std;
int main()
{
 void sort(int &,int &,int &);
 int a,b,c;
 cin>>a>>b>>c;
 sort(a,b,c);
 cout<<a<<” ”<<b<<” ”<<c;
 return 0;
}
void sort(int &c,int &d,int &e)
{
  void swap(int &,int &);
  if(c>d) swap(c,d);
  if(c>e) swap(c,e);
  if(d>e) swap(d,e);
}
void swap(int &x,int &y)
{
 int t;
 t=x;
 x=y;
 y=t;}
 
10. #include <iostream>
#include <string>
using namespace std;
int main()
{
 string s1="Thank",s2="you";
 s1=s1+s2;
 cout<<"The new string is:"<<s1<<endl;
 return 0;
}
 
11. #include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
int i,n;
char t;
cin>>s;
n=s.size();
for(i=0;i<n/2;i++)
{
 t=s[i];
 s[i]=s[n-i-1];
 s[n-i-1]=t;
}
cout<<s<<endl;
return 0;
}
 
 12.#include <string>
using namespace std;
int main()
{
 int i;
 string str[5]={"China","American","Japan","Korea","Y"};
 void sort(string[]);
 sort(str);
 for(i=0;i<5;i++)
 cout<<str[i]<<""<<endl;
 return 0;
}
void sort(string s[])
{
 int i,j;
 string t;
 for(j=0;j<5;j++)
 for(i=0;i<5-j;i++)
 if(s[i]>s[i+1])
 {t=s[i];s[i]=s[i+1];s[i+1]=t;}
}
 
13. #include <iostream>
using namespace std;
int main()
{
long a[5]={10100,-123567.1198783,-165654,3456};
int b[5]={1,9,8,3,4};
float c[5]={2.4,1.5,3.6,2.8,4.8};
void sort(long[]);
sort(a);
void sort(int[]);
sort(b);
void sort(float[]);
sort(c);
return 0;
}
void sort(long a[])
{
  int i,j;
  long t;
  for(j=0;j<5;j++)
  for(i=0;i<5-j;i++)
  if(a[i]>a[i+1])
  {
   t=a[i];
   a[i]=a[i+1];
   a[i+1]=t;
  }
  cout<<"The sorted numbers:"<<endl;
  for(i=0;i<5;i++)
  cout<<a[i]<<" "<<endl;
}
void sort(int b[])
{
  int i,j;
  int t;
  for(j=0;j<5;j++)
  for(i=0;i<5-j;i++)
  if(b[i]>b[i+1])
  {
   t=b[i];
   b[i]=b[i+1];
   b[i+1]=t;
  }
  cout<<"The sorted numbers:"<<endl;
  for(i=0;i<5;i++)
  cout<<b[i]<<" "<<endl;
}
void sort(float c[])
{
  int i,j;
  float t;
  for(j=0;j<5;j++)
  for(i=0;i<5-j;i++)
  if(c[i]>c[i+1])
  {
   t=c[i];
   c[i]=c[i+1];
   c[i+1]=t;
  }
  cout<<"The sorted numbers:"<<endl;
  for(i=0;i<5;i++)
  cout<<c[i]<<" "<<endl;
}
 
14.
#include <iostream>
using namespace std;
template <typename T>
void sort(T [])
{
 int a[5];
 int i,j,min;
 T t;
 for(i=0;i<5;i++)
 {
       min=i;
   for(j=i+1;j<5;j++)
   if(a[min]>a[j])
   min=j;
   t=a[i];
   a[i]=a[min];
   a[min]=t;
    }
}
int main()
{
int i;
    long a[5]={10100,-123567.1198783,-165654,3456};
int b[5]={1,9,8,3,4};
float c[5]={2.4,1.5,3.6,2.8,4.8};
sort(a);
    for(i=0;i<5;i++)
cout<<a[i]<<" "<<endl;
sort(b);
    for(i=0;i<5;i++)
cout<<b[i]<<" "<<endl;
    sort(c);
    for(i=0;i<5;i++)
    cout<<c[i]<<" "<<endl;
    return 0;
}
 
 
2. #include <iostream>
using namespace std;
class Time
{
public:
void set_time(void)
{
  cin>>hour>>minute>>sec;
}
void show_time(void)
{
 cout<<hour<<":"<<minute<<":"<<sec;
}
private:
int hour,minute,sec;
};
Time t;
int main()
{
 t.set_time();
 t.show_time();
 return 0; 
}
 
3. #include <iostream>
using namespace std;
class Time
{
public:
void set_time(void);
void show_time(void);
private:
int hour,minute,sec;
};
void Time :: set_time(void)
{
  cin>>hour>>minute>>sec;
}
void Time :: show_time(void)
{
 cout<<hour<<":"<<minute<<":"<<sec;
}
Time t;
int main()
{
 t.set_time();
 t.show_time();
 return 0; 
}
 
4. #include <iostream>
#include <string>
using namespace std;
class Student
{
public:
void display();
void set_value();
private:
int num;
    string name;
char sex;
};
int main()
{
 Student stud;
 stud.set_value();
 stud.display();
 return 0;
}
void Student :: display()
{
 cout<<"nunm:"<<num<<endl;
 cout<<"name:"<<name<<endl;
 cout<<"sex:"<<sex<<endl;
}
void Student :: set_value()
{
 cin>>num>>name>>sex;
}
 
 
 
6. #include <iostream>
using namespace std;
class  Cuboid
{public:
         void get_value();
         void volume();
         void display();
private:
     float length,width,height,vol;
};
void Cuboid ::get_value()
{
 cin>>length>>width>>height;
};
void Cuboid ::volume()
{
 vol=length*width*height;
}
void Cuboid ::display()
{
 cout<<vol<<endl;
}
int main()
{
 Cuboid c1,c2,c3;
 c1.get_value();
 c1.volume();
 cout<<"The volume of c1 is:";
 c1.display();
 c2.get_value();
 c2.volume();
 cout<<"The volume of c2 is:";
 c2.display();
 c3.get_value();
 c3.volume();
 cout<<"The volume of c3 is:";
 c3.display();
 return 0;
}
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值