#include <iostream>
#include <string>
using namespace std;
struct CandyBar
{
 //string kind;
 char kind[20];
 float weight;
 double calory;
};
void Display(CandyBar ca,int n)
{
    cout<<"The kind of ca["<<n<<"] is: "<<ca.kind<<endl;
 cout<<"The weight of ca["<<n<<"] is: "<<ca.weight<<endl;
 cout<<"The calory of ca["<<n<<"] is: "<<ca.calory<<endl;
}

int main()
{
 int size;
 cout<<"Enter the size of the array: ";
 cin>>size;
 cin.get();
 CandyBar *ca=new CandyBar[size];
 //getline(cin,ca[0].kind);
 cin.get(ca[0].kind,20).get();
 ca[0].weight=200;
 ca[0].calory=100;//getline(cin,ca[1].kind);//
  
 cin.get(ca[1].kind,20).get();
 ca[1].weight=205;
 ca[1].calory=105;//getline(cin,ca[2].kind);//
 
 cin.get(ca[2].kind,20).get();
 ca[2].weight=210;
 ca[2].calory=110;
 
 Display(ca[0],0);
 Display(ca[1],1);
 Display(ca[2],2);
 system("pause");
 return 0;
}

编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习9的更多相关文章

  1. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习9

    #include <iostream> #include <fstream> #include <cstdlib> #include <string> ...

  2. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习8

    #include <iostream> #include <fstream> #include <cstdlib> const int SIZE=20; using ...

  3. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习7

    #include <iostream> #include <string> #include <cctype> using namespace std; int m ...

  4. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习6

    #include <iostream> #include <string> using namespace std; const int MSIZE=100; struct j ...

  5. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习5

    #include <iostream> using namespace std; const double N1=35000; const int N2=15000; const int ...

  6. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习4

    #include <iostream> using namespace std; const int strsize=30; const int BOPSIZE=5; void showm ...

  7. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习3

    #include <iostream> using namespace std; void showmenu(void) { cout<<"Please enter ...

  8. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习2

    #include <iostream> #include <cctype> using namespace std; const int MAXSIZE=10; int mai ...

  9. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习1

    #include <iostream>#include <cctype>using namespace std;int main(){ char ch; while((ch=c ...

  10. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习9

    #include <iostream>using namespace std;int main(){ int num; cout<<"Enter number of ...

随机推荐

  1. paython3-练习

    在文本每行末尾加; f = open(r'D:\test1\1.txt','rb') w = open(r'D:\test1\2.txt','wb') for line in f.readlines( ...

  2. 树递归写法ref实现

    using System; using System.Collections.Generic; using System.Linq; namespace ConsoleAppTest { class ...

  3. [转] css3变形属性transform

    w3c上的例子是这样子写的:· div { transform:rotate(7deg); -ms-transform:rotate(7deg); /* IE 9 */ -moz-transform: ...

  4. java抽象类详解

    前言 在没讲抽象类之前  我们先来看看 final关键字 final 修饰符 可以修饰 类.属性.方法 修饰类时  表示该类不能被继承   其他特征 跟普通的类一样 修饰 属性时 表示 改属性不能改变 ...

  5. Asp.Net Mvc 返回类型总结

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  6. FastJson 支持配置的PropertyNamingStrategy四种策略

    摘要: FastJson默认使用CamelCase,在1.2.15版本之后,FastJson支持配置PropertyNamingStrategy,支持四种策略: CamelCase.PascalCas ...

  7. redis 配置文件配置

    redis的配置和使用 redis的配置的分段的 配置段: 基本配置项 网络配置项 持久化相关配置 复制相关的配置 安全相关配置 Limit相关的配置 SlowLog相关的配置 INCLUDES Ad ...

  8. Noj - 在线强化训练2

    状态 题号 竞赛题号 标题   1572 A 九鼎之尊(一)   1573 B 九鼎之尊(二)   1453 C 筛法(Sieve Method)   1134 D 亲密数(close numbers ...

  9. scrapy安装

    1.scrapy的安装 -前提,最好用virtualenv 创建的虚拟环境安装 -windows -官方推荐用anaconda -自定已安装 -1.https://www.lfd.uci.edu/~g ...

  10. thinkphp5控制器

    // 定义应用目录 define('APP_PATH', __DIR__ . '/../app/'); // 定义配置文件目录和应用目录同级 define('CONF_PATH', __DIR__.' ...