zoukankan      html  css  js  c++  java
  • 利用流格式控制,进行成绩和名字的输出,要求名字左对齐,分数右对齐--p209_1

    源程序:

    #include < iostream >

    #include < string >

    #include <iomanip>

    using namespace std;

    class Student //定义学生类

    {

    private:

      string name; //学生姓名

      float score; //学生成绩

    public:

      Student(string n = 0, float s = 0) //带默认参数的构造函数

      {

        name = n;

        score = s;

      }

      string getName()

      {

        return name;

      }

      float getScore()

      {

        return score;

      }

    };

    void main()

    {

      Student s1("liming", 98);  //建立5个学生对象

      Student s2("sdfh", 90);

      Student s3("vn.fy", 80);

      Student s4("cnbtrt", 70);

      Student s5("ryuety", 48);

      cout << setw(10) << left << "姓名" << setw(5) << right << "分数" << endl;

      cout << setw(10) << left << s1.getName() << setw(5) << right << s1.getScore() << endl;

      cout << setw(10) << left << s2.getName() << setw(5) << right << s2.getScore() << endl;

      cout << setw(10) << left << s3.getName() << setw(5) << right << s3.getScore() << endl;

      cout << setw(10) << left << s4.getName() << setw(5) << right << s4.getScore() << endl;

      cout << setw(10) << left << s5.getName() << setw(5) << right << s5.getScore() << endl;

      //设置名字的输出宽度为10,左对齐; 成绩的输出宽度为5,右对齐。

      system("pause");

    }

    运行结果:

     

  • 相关阅读:
    Pod镜像拉取策略imagePullPolicy
    部署helm服务
    查看k8s中etcd数据
    k8s RBAC实践
    部署k8s集群监控Heapster
    编译k8s1.11 kube-apiserver源码
    阿里云跨地域访问私网
    阿里云ECS搭建harbor1.6.1仓库
    JavaScript
    前端之网络协议、浏览器
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11900237.html
Copyright © 2011-2022 走看看