第一章节
来源:互联网 发布:怎么优化群排名 编辑:程序博客网 时间:2024/04/18 18:35
第一章
7.
#include<iostream>
using namespace std;
int main()
{ int max(int x=4,int y=9);
int a,b,c;
c=max();
cout<<c<<endl;
return 0;
}
int max(int x,int y)
{
int z;
if (x>y)z=x;
else z=y;
return(z);
}
8.
#include<iostream>
using namespace std;
int main()
{ int a,b;
cin>>a>>b;
int &c=a;
int &d=b;
if(a>b)
cout<<c<<d;
else
cout<<d<<c;
}
9.
#include<iostream>
using namespace std;
int main()
{ int a,b,c;
cin>>a>>b>>c;
int &l=a;
int &m=b;
int &s=c;
int temp;
if (a<b) {temp=a;a=b;b=temp;}
if(c>a) cout<<s<<l<<m;
else if(c>b) cout<<l<<s<<m;
else cout<<l<<m<<s;
}
10.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1,str2;
cin>>str1>>str2;
str1=str1+str2;
cout<<str1;
}
11.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1;
cin>>str1;
int i=5;
for(i;i<6;i--)
cout<<str1[i];
}
12.
#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];
cout<<"The sorted string is:"<<endl;
for(i=0;i<=5;i++)
cout<<str[i]<<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;
}
}
14..#include<iostream>
using namespace std;
template<typename T>
paixu(T*a,int n)
{ for(int 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(int i=0;i<n;i++)
cout<<a[i]<<endl;
}
int main()
{
int a[5],n;
n=sizeof(a)/sizeof(int);
for(int i=0;i<n;i++)
cin>>a[i];
paixu(a,n);
}
第三章
4.
#include<iostream>
using namespace std;
class student
{
public:
int num;
int score;
void display();
void get();
};
void student::get()
{
cin>>num;
cin>>score;
}
void student::display()
{
cout<<num<<" "<<score<<endl;
}
int main()
{
student stud[5];
for(int i=0;i<5;i++)
{
stud[i].get();
}
student *p;
p=&stud[0];
p->display();
p+=2;
p->display();
p+=2;
p->display();
}
5.
#include<iostream>
using namespace std;
class student
{
public:
int num;
int score;
void get();
};
void student::get()
{
cin>>num;
cin>>score;
}
int max(student *p)
{ int max;
for(int i=0;i<5;i++)
{
if(p->score<++p->score)
max=++p->score;
else max=p->score;
p++;
}
cout<<max;
}
int main()
{ student stud[5];
student *p;
p=&stud[1];
for(int i=0;i<5;i++)
{
stud[i].get();
}
max(p);
}
8.
#include <iostream>
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s)
{num=n;score=s;}
void display()
{cout << num <<" " << score <<endl;}
private:
int num;
float score;
};
void fun(Student &stud)
{
stud.display();
stud.change(101,80.5);
stud.display();
}
int main()
{
Student stud(101,78.5);
fun(stud);
return 0;
}
9.
#include <iostream>
using namespace std;
class salesman
{
public:
salesman()//构造函数
{
quantity=0; //初始化
price=0;
}
static float average();
static void display();
void total();
void set();
private:
static float discount;
static float sum;
static int n;
int quantity;
float price;
};
void salesman::set()
{
cout<<"销售件数"<<endl;
cin>>quantity;
cout<<"售货单价"<<endl;
cin>>price;
}
void salesman::total()
{ if(quantity>=10)
price=price*0.98;
sum+=quantity*price*discount; //打折折扣后价钱
n+=quantity;
}
float salesman::average()
{
return(sum/n);
}
float salesman::discount=0.9;
int salesman::n=0;
float salesman::sum=0;
void salesman::display()
{
cout<<"总销售款为"<<sum<<endl;
cout<<"平均售价为"
<<salesman::average()
<<endl;
}
int main()
{
salesman sal[3];
sal[0].set();
sal[0].total();
sal[1].set();
sal[1].total();
sal[2].set();
sal[2].total();
salesman::display();
}
10.
#include <iostream>
using namespace std;
class Date;
class Time{
public:
Time(int ,int ,int);
friend void display(Time &);
private:
int hour;
int minute;
int sec;
};
class Date{
public:
Date(int ,int ,int);
friend void display(Date &);
private:
int mouth;
int day;
int year;
};
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}
void display(Date &d)
{
cout<<d.mouth<<"/"<<d.day<<"/"<<d.year<<"/"<<endl;
}
void display(Time &d)
{
cout<<d.hour<<":"<<d.minute<<":"<<d.sec<<endl;
}
Date::Date(int m,int d,int y)
{
mouth=m;
day=d;
year=y;
}
int main()
{
Time t1(10,13,56);
Date d1(12,25,2004);
display(t1);
display(d1);
return 0;
}
11.
#include <iostream>
using namespace std;
class Date;
class Time{
friend Date;
public:
Time(int ,int ,int);
void display(Date &);
private:
int hour;
int minute;
int sec;
};
class Date{
public:
Date(int ,int ,int);
friend void Time::display(Date &);
private:
int mouth;
int day;
int year;
};
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}
void Time::display(Date &d)
{
cout<<d.mouth<<"/"<<d.day<<"/"<<d.year<<"/"<<endl;
cout<<hour<<":"<<minute<<":"<<sec<<endl;
}
Date::Date(int m,int d,int y)
{
mouth=m;
day=d;
year=y;
}
int main()
{
Time t1(10,13,56);
Date d1(12,25,2004);
t1.display(d1);
return 0;
}
12..
#include <iostream>
using namespace std;
template<class numtype>
class compare//声明类模板
{public:
compare(numtype,numtype);
numtype max();
numtype min();
private:
numtype x,y;
};
template<class numtype>
compare<numtype>::compare( numtype a,numtype b)
{
x=a;
y=b;
}
template<class numtype>
numtype compare<numtype>::max()
{
return (x>y)?x:y;
}
template<class numtype>
numtype compare<numtype>::min()
{
return (x<y)?x:y;
}
int main( )
{compare <int> cmp1(3,7);
cout<<cmp1.max( )<<"is the Maximum of two integer numbers." <<endl;
cout<<cmp1.min( )<<"is the Minimum of two integer numbers."<<endl<<endl;
compare<float> cmp2(45.78,93.6);
cout<<cmp2.max( )<<" is the Maximum of two float numbers."<<endl;
cout<<cmp2.min( )<<"is the Minimum of two float numbers."<<endl<<endl;
compare<char> cmp3('a','A');
cout<<cmp3.max( )<<"is the Maximum of two characters." <<endl;
cout<<cmp3.min( )<<"is the Minimum of two characters."<<endl;
return 0;
}
- 第一章节
- Java第一章节
- 第一章节 android起航
- Java NIO 第一章节
- java的第一章节
- 第一章节 android知识准备
- HttpClient 第一章节 (初学者)
- html内容整理第一章节
- 个人学习第一章节:球吃豆
- 《Effective python》第一章节读后感
- 第一章节:Revit API基本概念
- 初学算法导论第一章节
- jsr之 servlet 2.5 第一章节
- NO3:步履蹒跚-完成第一章节学习
- Inside SP2010--第一章节--SP2010开发者路线图
- Expert SP2010 Practices--第一章节--工作流
- 《数据结构》第一章节绪论 问题回收站
- 《PHP权威指南》第一章节笔记
- 各种特殊矩阵的压缩存储
- 线性滤波:方框、均值、高斯
- 不定期更新ML学习笔记
- c语言实现快速排序
- VS2013串口通信
- 第一章节
- 迅游网游加速器2015完美和谐版
- hdu 5195 DZY Loves Topological Sorting && BestCoder Round #35
- .NET学习之静态类
- 2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest F. Ilya Muromets
- Ubuntu下配置zsh
- C语言实现双向循环链表
- windows 涉及到的简单socket API函数的用法
- 分析一个API的调用机制