学习C++ primer plus 第9章编程练习1
来源:互联网 发布:c盘中windows.old 编辑:程序博客网 时间:2024/06/08 14:47
main.cpp
#include"syx.h"using namespace std;const int MAX=3;golf*dg=new golf[MAX];golf ann;int main(){int i=0;for(i;i<MAX&&setgolf(dg[i]);i++);setgolf(ann,"Ann Birdfree",24);for(int j=0;j<i;j++)showgolf(dg[i]);showgolf(ann);delay(100);return 0;}
syx.h
#ifndef SYX_H_#define SYX_H_#include <iostream>#include<ctime>#include<cstring>void delay(float);const int Len = 40;struct golf{ char fullname[Len]; int handicap;};// non-interactive version;// function sets golf structure to provided name,handicap// using values passed as arguments to the functionvoid setgolf (golf & g, const char * name, int hc);// interactive version;// function solicits name and handicap from user// and sets the members of g to the values entered// returns 1 if name is entered, 0 if name is empty stringint setgolf( golf &g);// function resets handicap to new valuevoid handicap (golf & g,int hc);// function displays contents of golf structurevoid showgolf (const golf & g);#endiffun.cpp
#include"syx.h"void delay(float time){clock_t delay=time*CLOCKS_PER_SEC;clock_t start=clock();while(clock()-start<delay);}int setgolf( golf &g){std::cout<<"请输入选手姓名:";std::cin.getline(g.fullname,40);if(g.fullname[0]=='\0')return 0;std::cout<<"请输入选手等级";std::cin>>g.handicap;std::cin.get();return 1;}void setgolf (golf & g, const char * name, int hc){strcpy(g.fullname,name);handicap(g,hc);}void handicap (golf & g,int hc){g.handicap=hc;}void showgolf (const golf & g){std::cout<<"选手:"<<g.fullname<<"等级:"<<g.handicap<<std::endl;}
0 0
- 学习C++ primer plus 第9章编程练习1
- C Primer Plus 第9章 函数 编程练习
- C Primer Plus 第九章 编程练习 1-9题
- c++primer plus 第4章编程练习之路
- C.Primer.Plus(第六版)第10章 编程练习
- C.Primer.Plus(第六版)第11章 编程练习
- C.Primer.Plus(第六版)第12章 编程练习
- C.Primer.Plus(第六版)第13章 编程练习
- C.Primer.Plus(第六版)第14章 编程练习
- C.Primer.Plus(第六版)第15章 编程练习
- C.Primer.Plus(第六版)第16章 编程练习
- C.Primer.Plus(第六版)第17章 编程练习
- 《C Primer Plus(第5版)中文版》第7章编程练习第9题
- 《C Primer Plus(第5版)中文版》第6章编程练习第1题
- 《C Primer Plus(第5版)中文版》第7章编程练习第1题
- 【C++】学习笔记十四——C++ primer plus第六版第4章编程练习
- C Primer Plus 第6版 12章 练习9
- C Primer Plus第二章编程练习
- Android5.0 Activity的跳转动画
- tensorflow MLP
- 143. Reorder List
- 启动mysql出错:Can't find messagefile '/usr/share/mysql/errmsg.sys
- react native ios打包到真机
- 学习C++ primer plus 第9章编程练习1
- 数据挖掘-Iris数据集分析-决策边界(六)
- InfoGAN论文笔记+源码解析
- PLSQL Package Initialize Block
- removeEventListener('2016');
- 模型评估与选择
- 37-2-3
- pip安装使用详解
- Mysql入门学习笔记(2)----外键约束