码迷,mamicode.com
首页 > 编程语言 > 详细

C++Primer Plus习题记录-Chapter8

时间:2019-01-25 16:33:22      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:++   string   cin.get   double   mil   prim   style   name   int   

7-2

#include "pch.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cctype>
#include <array>
#include <iomanip>

using namespace std;
struct CandyBar
{
    string brand;
    double weight;
    int heat;
};
void info_candy(CandyBar &changed_para, char* str, double m, int n);
void show(CandyBar &candy);//test

int main() {
    CandyBar init_para = {
        "Millennium Munch",
        2.85,
        350
    };
    show(init_para);
    char ch[20];
    cin.getline(ch,20);
    double m;
    cin >> m;
    int n;
    cin >> n;
    info_candy(init_para, ch, m, n);
    show(init_para);
    return 0;
}
void info_candy(CandyBar &changed_para, char* str, double m, int n) {
    changed_para.brand = str;
    changed_para.weight = m;
    changed_para.heat = n;
}
void show(CandyBar &candy) {
    cout << candy.brand << "\n" << candy.weight << "\n" << candy.heat << endl;
}

 

C++Primer Plus习题记录-Chapter8

标签:++   string   cin.get   double   mil   prim   style   name   int   

原文地址:https://www.cnblogs.com/lightmonster/p/10320227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!