首页 > 其他分享 >第九天第一个问题

第九天第一个问题

时间:2023-04-21 19:36:45浏览次数:33  
标签:第九天 CandyBar bar 第一个 int double void 问题 char

问题描述:candy结构包含3个成员,第一个成员存储candy bar的品牌名称;第二个成员存储candy bar的重量;第三个成员存储candy bar的热量。编写一个程序,使用这样的函数,将结构引用,char指针double,int为参数,用最后3个值设置相应的结构成员。最后3个参数的默认值分别为“millennium munch”、2.85和350。

解决思路:

1.初始化结构体

2.编写两个函数,一个用于给结构体赋值,一个用于显示结构体成员数据

3.主函数主要是询问用户输入数据加之调用函数

代码:

#include <iostream>

#include <string>
using namespace std;
const int size = 30;
struct CandyBar {
string name;
double weight;
int rel;
};
void han(CandyBar& bar, const char* na = "Millennium", double we = 2.85, int re = 350);
void show(CandyBar bar);
int main() {
const int size = 20;
char ch[size];
cout << "enter name weight and rel:";
cin >> ch;
double weight1;
int rel1;
cin >> weight1;
cin >> rel1;
CandyBar bar1;
han(bar1, ch, weight1, rel1);
show(bar1);
return 0;
}
void han(CandyBar& bar,const char* na, double we, int re) {
bar.name = na; 
bar.weight = we;
bar.rel = re;
}
void show(CandyBar bar) {
cout << bar.name << "/" << bar.weight << "/" << bar.rel << endl;
}

标签:第九天,CandyBar,bar,第一个,int,double,void,问题,char
From: https://www.cnblogs.com/czfznb/p/17341496.html

相关文章

  • ocelot 注入consul 无法匹配路由的问题可能性
    ocelot注入consul无法匹配路由的问题可能性最近在搭建微服务,在服务的注册、发现和api的统一管理绕不开 ocelot 和 consul,在没有注入consul时,基础的配置文件能正常转发,但是注入consul后服务没有按照规定的上游路径来访问的情况(但是按照http://ip:port/consulName/api/user......
  • 打卡第九天
    输入一个整数,求出他的所有因子。一、1.定义变量,用于保存整数值。2、利用穷举法,找出1到整数值所有能够整除的数3、循环次数已知,利用for循环。二、三、#include<iostream>usingnamespacestd;intmain(){ intn,i; cout<<"输入整数值:"; cin>>n; for(i=1;i<=n;i++) { if(n......
  • day 12 存钱问题
    1.找到相关年份的限制条件(年总和不可以超过20);2.根据限制遍历所有情况(采用循环);3.定义Max记录最大值;4.输出 #include<iostream>usingnamespacestd;intx8,x5,x3,x2,x1;doublef(intnum,doublet,intm){doublesum=1;for(inti=0;i<m;i++){sum*=(1+nu......
  • centos没有vi命令 或者apt-get update很慢问题
    apt-getupdate很慢问题1.打开终端,进入目录:cd/etc/apt2.备份一下原来的source文件:mvsources.listsources.list.bak3.修改source.list文件,清空里面的内容,并复制以下内容进去:因为没有vi命令echo"debhttp://mirrors.aliyun.com/ubuntu/bionicmainrestrictedunive......
  • 关于 mysql 加了 limit 反而变慢的问题?
    SELECT*FROMpre_forum_postWHEREtid=6584344AND`inv`='0'AND`uid`='6547981'ORDERBYdatelineDESClimit4;上面一条正常执行需要16-20秒.SELECT*FROMpre_forum_postWHEREtid=6584344AND`inv`='0'AND`uid`='6547981'O......
  • python调用imgkit将html转图片pdf问题实例wkhtmltox
    wkhtmltox的下载地址:https://wkhtmltopdf.org/downloads.html或者:https://github.com/wkhtmltopdf/wkhtmltopdf0.12.6版本按网络上的教程会出现一个错误:IOError:wkhtmltopdfexitedwithnon-zerocode1.error:[blank]解决方法参见:https://stackoverflow.com/questions/......
  • OA 问题统计
    一.无法修改操作组、只能新建成本中心......
  • Android Studio Gradle Download 慢/卡问题解决
    build.gradlebuildscript{repositories{//jcenter()//jcenter(){url'http://jcenter.bintray.com/'}maven{url'http://maven.aliyun.com/nexus/content/groups/public/'}maven{url"https://jitpac......
  • 服务器CPU过高问题排查-
    情况描述实验部门反馈,190上数据本地盘拷贝数据,和数据拆分速度比之前慢了一倍。  数据拷贝用时情况:登入190服务器输入top命令,发现load值非常高,Cpu的usespace达到100,说明后台有很多用户程序在跑。但是用top在后台没有看到特别高的进程。 $toploadaverage:......
  • 记一次jedis连接池顽固问题排查与修改
    这辈子不想再看到jedisBrokenPipe!! 测试环境运行16天后报错信息:05:42:32.629[http-nio-8093-exec-2]ERRORo.a.c.c.C.[.[.[.[dispatcherServlet]-[log,175]-Servlet.service()forservlet[dispatcherServlet]incontextwithpath[]threwexception[Requestproces......