鱼C论坛

 找回密码
 立即注册

C++Primer Plus 第六版编程练习7.13-8(1)

已有 92 次阅读2015-7-4 02:21 |个人分类:c++Primer Plus 第6版编程练习笔记| Plus

//方案1
#include <iostream>

using namespace std ;
const int Seasons = 4 ;
const char str1[Seasons][10] = {"Spring" ,"Summer","Fall","Winter"} ;

void fill( int num[] ,int n) ;
void show(int num[],int n) ;

int main()
{
    int num[Seasons] ;
    fill(num ,Seasons) ;
    show(num ,Seasons) ;
    return 0 ;
}

void fill( int num[] ,int n)
{
    for(int i =0 ;i< n ;i++)
    {
        cout<<"Enter "<<str1[i] <<" expenses: ";
        cin>>num[i] ;
    }
}

void show(int num[],int n)
{
    double total = 0.0 ;
    cout<<"\nEXPENSES\n" ;
    for(int i =0 ;i< n ;i++)
    {
        cout<<str1[i]<<": $" <<num[i]<<endl ;
        total += num[i] ;
    }
    cout<<"Total Exoenses: $"<<total<<endl ;
}





路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 18:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部