当前位置: 首页 > wzjs >正文

关于网站建设广告词电商网站建设哪家好

关于网站建设广告词,电商网站建设哪家好,做网站系统学校,浙江网站制作公司6-1 数组排序输出(函数模板) 对于输入的每一批数,按从小到大排序后输出。 一行输入为一批数,第一个输入为数据类型(1表示整数,2表示字符型数,3表示有一位小数的浮点数,4表示字符串…

6-1 数组排序输出(函数模板)

对于输入的每一批数,按从小到大排序后输出。

一行输入为一批数,第一个输入为数据类型(1表示整数,2表示字符型数,3表示有一位小数的浮点数,4表示字符串,0表示输入结束),第二个输入为该批数的数量size(0<size<=10),接下来为size个指定类型的数据。

输出将从小到大顺序输出数据。

代码清单:

#include <iostream>

#include <string>

using namespace std;

/* 请在这里填写答案 */

template<class TA>

void sort(TA* a,int size)

{

    for(int k=0;k<size;k++)

    {

        cin>>a[k];

    }

    TA temp=a[0];

    for(int i=0;i<size;i++)

    {

        for(int j=i+1;j<size;j++)

        {

            if(a[i]>a[j])

            {

                temp=a[i];

                a[i]=a[j];

                a[j]=temp;

            }

        }

    }

}

template <class T>

void display(T* a, int size){

    for(int i=0; i<size-1; i++) cout<<a[i]<<' ';

    cout<<a[size-1]<<endl;

}

int main() {

     const int SIZE=10;

     int a[SIZE];

     char b[SIZE];

     double c[SIZE];

     string d[SIZE];

     int ty, size;

     cin>>ty;

     while(ty>0){

         cin>>size;

         switch(ty){

             case 1:sort(a,size); display(a,size); break;

             case 2:sort(b,size); display(b,size); break;

             case 3:sort(c,size); display(c,size); break;

             case 4:sort(d,size); display(d,size); break;

         }

         cin>>ty;

     }

      return 0;

}

运行结果截图

题目2(给出题目描述)

7-1 车辆计费#include<iostream>

代码清单:

#include<string>

using namespace std;

class Vehicle{

protected:

    string NO;

public:

    Vehicle(string str)

    {

        NO=str;

    }

    virtual void display()=0;

};

class Car:public Vehicle{

    int num;

    int kg;

    public:

    Car(string str,int _num,int _kg):Vehicle(str)

    {

        num=_num;

        kg=_kg;

    }

    virtual void display()

    {

        cout<<NO<<" "<<num*8+kg*2<<endl;

    }

};

class Truck:public Vehicle{

    int kg;

    public:

    Truck(string str,int _kg):Vehicle(str)

    {

        kg=_kg;

    }

    virtual void display()

    {

        cout<<NO<<" "<<kg*5<<endl;

    }

};

class Bus:public Vehicle{

    int num;

    public:

    Bus(string str,int _num):Vehicle(str)

    {

        num=_num;

    }

    virtual void display()

    {

        cout<<NO<<" "<<num*3<<endl;

    }

};

int main()

{

    Vehicle *pv[10];

    string str;

    int t,num,kg,i=0;

    cin>>t;

    while(t!=0)

    {

        cin>>str;

        if(t==1)

        {

            cin>>num>>kg;

            pv[i]=new Car(str,num,kg);

        }else if(t==2){

            cin>>kg;

            pv[i]=new Truck(str,kg);

        }else if(t==3){

            cin>>num;

            pv[i]=new Bus(str,num);

        }

        pv[i]->display();

        i++;

        cin>>t;

    }

    return 0;

}

运行结果截图

题目3给出题目描述)

7-2 复数类模板

代码清单:

#include <iostream>

using namespace std;

template <class TA>

class Complex

{

private:

 TA real;

 TA image;

public:

 Complex(TA r = 0, TA i = 0) : real(r), image(i) { };

 void Show() const;

 Complex Add(const Complex& z2);

};

template <class TA>

void Complex<TA>::Show() const

{

 cout << "(" << real << ", " << image << ")";

}

template <class TA>

Complex<TA> Complex<TA>::Add(const Complex& z2)

{

 float r, i;

 r = this->real + z2.real;

 i = this->image + z2.image;

 Complex z(r, i);

 return z;

}

int main()

{

 float x1=0, x2=0, y1=0, y2=0;

 cin >> x1 >> y1;

 cin >> x2 >> y2;

 Complex<float> z1(x1, y1), z2(x2, y2);

 (z1.Add(z2)).Show();

 return 0;

}

运行结果截图

http://www.dtcms.com/wzjs/491336.html

相关文章:

  • 做网站怎么开发程序汕头seo计费管理
  • 网站建设 策划方案书网站推广的案例
  • wordpress网站多语言包想学网络营销怎么学
  • ukidc做电影网站seo干什么
  • 莱芜高端网站设计建设数据分析软件
  • 建筑行业教育培训平台站长之家seo工具包
  • 云南网站建设哪家强管理培训
  • 美国做任务挣钱的网站seo网站整站优化
  • 珠海做网站公司杭州百度代理公司
  • 沈阳网站的建设外贸seo推广公司
  • 推广品牌的策划方案北京做网络优化的公司
  • 怎么开公众号重庆优化seo
  • 专门帮忙做网站的公司推广赚钱的项目
  • 富平做网站优化网站打开速度
  • 云南做网站找谁西安百度快速排名提升
  • 如何建设网站兴田德润怎么联系seo职业技能培训班
  • wordpress app模板下载公司优化是什么意思
  • 网站推广常用方法有哪些seo专业推广
  • 怎样做公司的网站建设长尾词挖掘工具
  • 网站运营合同抖音搜索引擎优化
  • 许昌住房建设局的网站实体店怎么推广引流
  • 建设网站模板搜索引擎优化理解
  • 关于网站建设的案例分析优化网站推广教程排名
  • 重庆网站建设cqhtwlseo外链优化培训
  • ps做网站要求成都新一轮疫情
  • 做网站的图片c盘优化大师
  • 辽宁城乡和住房建设部网站友博国际个人中心登录
  • 建站公司有哪些服务营销战略
  • 龙岗网站设计案例seo培训网
  • 安徽网站开发项目和业务多一样的平台