作业0327
来源:互联网 发布:软件商城建设 编辑:程序博客网 时间:2024/05/22 13:44
P35 T7
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z);
cin>>a>>b>>c;
c=f(a,b,c);
cout<<c<<endl;
return 0;
}
int f(int x,int y,int z)
{
int m;
if(x>y)
m=x;
else m=y;
if (z>m)
m=z;
return(m);
}
T8
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;
if (x>y)
cout<<x<<","<<y<<endl;
else cout<<y<<","<<x<<endl;
return 0;
}
T9
#include <iostream>
using namespace std;
int main()
{
void sort(int x,int y,int z);
int x,y,z;
cin>>x>>y>>z;
sort(x,y,z);
return 0;
}
void sort(int x,int y,int z)
{
int temp;
if(x>y)
{ temp=x;x=y;y=temp;}
if (z<x) cout<<z<<","<<x<<","<<y<<endl;
else if(z<y) cout<<x<<","<<z<<","<<y<<endl;
else cout<<x<<","<<y<<","<<z<<endl;
}
T10
#include<iostream>
#include<string.h>
using namespace std;
main()
{
char a[20]="1234";
char b[]="abcd";
strcat(a,b);
cout<<a<<endl;
}
T11
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
string str;
cout<<"请输入一串字符:"<<endl;
cin>>str;
cout<<"字符串倒序后为:"<<endl;
for(i=str.length()-1;i>=0;i--)
cout<<str[i];
cout<<endl;
system("pause");
return 0;
}
T12
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i;
string str[5];
void sort(string s[]);
cout<<"Please input string:"<<endl;
for(i=0;i<5;i++)
cin>>str[i];
sort(str);
cout<<"The sorted string is:"<<endl;
for(i=0;i<=5;i++)
cout<<str[i]<<" ";
cout<<endl;
return 0;
}
void sort(string s[])
{
int i,j;
string temp;
for(i=0;i<4;i++)
for(j=0;j<4-i;j++)
if(s[j]>s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
T13
#include<iostream>
using namespace std;
template <typename Type>
void sort(Type* cp);
int main()
{
int a[5]={1,9,0,23,-45};
float b[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
long int c[5]={10100,-123567, 1198783,-165654, 3456};
sort(a);
sort(b);
sort(c);cin.get();
return 0;
}
template <typename Type>
void sort(Type* cp)
{
int i,j;
Type temp;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(cp[j]>cp[j+1])
{temp=cp[j];
cp[j]=cp[j+1];
cp[j+1]=temp;}
}
}
for(i=0;i<5;i++)
cout<<cp[i]<<" ";
cout<<endl;
}
t14
#include<iostream>
using namespace std;
template<typename T>
T paixu(T*a,int n)
{
int i;
for(i=0;i<n;i++){
for(int j=0;j<n;j++){
if(a[i]<a[j]){
T temp=a[i];
a[i]=a[j];
a[j]=temp;}}}
for(i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
}
int main()
{
int a[5],n;
n=sizeof(a)/sizeof(int);
for(int i=0;i<n;i++) cin>>a[i];
paixu(a,n);
system("pause");
return 0;
}
p67t2
#include "iostream"
using namespace std;
class Time
{
private:
int hour;
int min;
int sec;
public:
void shuru()
{
cin>>hour;
cin>>min;
cin>>sec;
cout<<hour<<":"<<min<<":"<<sec<<endl;
}
};
int main()
{
Time t;
t.shuru();
return 0;
}
t3
#include "iostream"
using namespace std;
class Time
{
private:
int hour;
int min;
int sec;
public:
void shuru();
};
void Time::shuru()
{
cin>>hour;
cin>>min;
cin>>sec;
cout<<hour<<":"<<min<<":"<<sec;
}
int main()
{
Time t;
t.shuru();
return 0;
}
t4
#include<iostream>
#include<string>
using namespace std;
void set_value(int a,string b,char c)
{
cout<<"分别输入学号,姓名,性别:"<<endl;
cin>>a>>b>>c;
}
class student
{
private:
int num;
string name;
char sex;
set_value(int num,string name,char sex);
public:
void display()
{
cout<<"num"<<endl;
cout<<"name"<<endl;
cout<<"sex"<<endl;
}
};
main()
{
student stu;
return 0;
}
作业p67t6
#include "iostream"
using namespace std;
class cfx
{
public:
int chang;
int kuan;
int gao;
};
int tiji(int a,int b,int c)
{
int t;
t=a*b*c;
cout<<"体积:"<<t<<endl;
return t;
}
int main()
{
cfx c1;
cout<<"输入长宽高:"<<endl;
cin>>c1.chang;
cin>>c1.kuan;
cin>>c1.gao;
cout<<"长:"<<c1.chang<<" 宽:"<<c1.kuan<<" 高:"<<c1.gao<<endl;
tiji(c1.chang,c1.kuan,c1.gao);
cfx c2;
cout<<"输入长宽高:"<<endl;
cin>>c2.chang;
cin>>c2.kuan;
cin>>c2.gao;
cout<<"长:"<<c2.chang<<" 宽:"<<c2.kuan<<" 高:"<<c2.gao<<endl;
tiji(c2.chang,c2.kuan,c2.gao);
cfx c3;
cout<<"输入长宽高:"<<endl;
cin>>c3.chang;
cin>>c3.kuan;
cin>>c3.gao;
cout<<"长:"<<c3.chang<<" 宽:"<<c3.kuan<<" 高:"<<c3.gao<<endl;
tiji(c3.chang,c3.kuan,c3.gao);
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z);
cin>>a>>b>>c;
c=f(a,b,c);
cout<<c<<endl;
return 0;
}
int f(int x,int y,int z)
{
int m;
if(x>y)
m=x;
else m=y;
if (z>m)
m=z;
return(m);
}
T8
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;
if (x>y)
cout<<x<<","<<y<<endl;
else cout<<y<<","<<x<<endl;
return 0;
}
T9
#include <iostream>
using namespace std;
int main()
{
void sort(int x,int y,int z);
int x,y,z;
cin>>x>>y>>z;
sort(x,y,z);
return 0;
}
void sort(int x,int y,int z)
{
int temp;
if(x>y)
{ temp=x;x=y;y=temp;}
if (z<x) cout<<z<<","<<x<<","<<y<<endl;
else if(z<y) cout<<x<<","<<z<<","<<y<<endl;
else cout<<x<<","<<y<<","<<z<<endl;
}
T10
#include<iostream>
#include<string.h>
using namespace std;
main()
{
char a[20]="1234";
char b[]="abcd";
strcat(a,b);
cout<<a<<endl;
}
T11
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
string str;
cout<<"请输入一串字符:"<<endl;
cin>>str;
cout<<"字符串倒序后为:"<<endl;
for(i=str.length()-1;i>=0;i--)
cout<<str[i];
cout<<endl;
system("pause");
return 0;
}
T12
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i;
string str[5];
void sort(string s[]);
cout<<"Please input string:"<<endl;
for(i=0;i<5;i++)
cin>>str[i];
sort(str);
cout<<"The sorted string is:"<<endl;
for(i=0;i<=5;i++)
cout<<str[i]<<" ";
cout<<endl;
return 0;
}
void sort(string s[])
{
int i,j;
string temp;
for(i=0;i<4;i++)
for(j=0;j<4-i;j++)
if(s[j]>s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
T13
#include<iostream>
using namespace std;
template <typename Type>
void sort(Type* cp);
int main()
{
int a[5]={1,9,0,23,-45};
float b[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
long int c[5]={10100,-123567, 1198783,-165654, 3456};
sort(a);
sort(b);
sort(c);cin.get();
return 0;
}
template <typename Type>
void sort(Type* cp)
{
int i,j;
Type temp;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(cp[j]>cp[j+1])
{temp=cp[j];
cp[j]=cp[j+1];
cp[j+1]=temp;}
}
}
for(i=0;i<5;i++)
cout<<cp[i]<<" ";
cout<<endl;
}
t14
#include<iostream>
using namespace std;
template<typename T>
T paixu(T*a,int n)
{
int i;
for(i=0;i<n;i++){
for(int j=0;j<n;j++){
if(a[i]<a[j]){
T temp=a[i];
a[i]=a[j];
a[j]=temp;}}}
for(i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
}
int main()
{
int a[5],n;
n=sizeof(a)/sizeof(int);
for(int i=0;i<n;i++) cin>>a[i];
paixu(a,n);
system("pause");
return 0;
}
p67t2
#include "iostream"
using namespace std;
class Time
{
private:
int hour;
int min;
int sec;
public:
void shuru()
{
cin>>hour;
cin>>min;
cin>>sec;
cout<<hour<<":"<<min<<":"<<sec<<endl;
}
};
int main()
{
Time t;
t.shuru();
return 0;
}
t3
#include "iostream"
using namespace std;
class Time
{
private:
int hour;
int min;
int sec;
public:
void shuru();
};
void Time::shuru()
{
cin>>hour;
cin>>min;
cin>>sec;
cout<<hour<<":"<<min<<":"<<sec;
}
int main()
{
Time t;
t.shuru();
return 0;
}
t4
#include<iostream>
#include<string>
using namespace std;
void set_value(int a,string b,char c)
{
cout<<"分别输入学号,姓名,性别:"<<endl;
cin>>a>>b>>c;
}
class student
{
private:
int num;
string name;
char sex;
set_value(int num,string name,char sex);
public:
void display()
{
cout<<"num"<<endl;
cout<<"name"<<endl;
cout<<"sex"<<endl;
}
};
main()
{
student stu;
return 0;
}
作业p67t6
#include "iostream"
using namespace std;
class cfx
{
public:
int chang;
int kuan;
int gao;
};
int tiji(int a,int b,int c)
{
int t;
t=a*b*c;
cout<<"体积:"<<t<<endl;
return t;
}
int main()
{
cfx c1;
cout<<"输入长宽高:"<<endl;
cin>>c1.chang;
cin>>c1.kuan;
cin>>c1.gao;
cout<<"长:"<<c1.chang<<" 宽:"<<c1.kuan<<" 高:"<<c1.gao<<endl;
tiji(c1.chang,c1.kuan,c1.gao);
cfx c2;
cout<<"输入长宽高:"<<endl;
cin>>c2.chang;
cin>>c2.kuan;
cin>>c2.gao;
cout<<"长:"<<c2.chang<<" 宽:"<<c2.kuan<<" 高:"<<c2.gao<<endl;
tiji(c2.chang,c2.kuan,c2.gao);
cfx c3;
cout<<"输入长宽高:"<<endl;
cin>>c3.chang;
cin>>c3.kuan;
cin>>c3.gao;
cout<<"长:"<<c3.chang<<" 宽:"<<c3.kuan<<" 高:"<<c3.gao<<endl;
tiji(c3.chang,c3.kuan,c3.gao);
return 0;
}
0 0