钱能C++教材习题答案四

   /2005-05-08

闁绘劗鎳撻崵顔剧博鐎n亜绁柟鍏肩矌閸岋拷2濞戞挸娲ㄩ~鎺楁嚀閸愵亞鍩¢柣銏ゆ涧閻℃瑩鎮ч崼锝囥偒闁哄倹鐟辩槐锟�
濠㈠爢鍥у姤闁告帒妫涢銏ゆ鐎n喖鍘撮柡鍕靛灣椤戝洦绋夐埀顒€鈻庨檱閳ь剙鍟伴悥娲晬鐏炵瓔鍤犲ù婊冮椤┭勬媴閺囩喓鍙€闁归潧褰炵粭鎾寸▔濮樻剚鍤﹂柟绋挎搐閻i箖寮▎鎰稄闁挎稑鏈崹銊ф媼閸涘﹥绠掔€垫澘鐗嗛ˇ鍧楁偪閹达附锛栭柕鍡曞ree濠㈠綊鈧稒銆冮柛鎺戞椤掔喐绋婇悩鐢电Ч闁兼澘鍟伴悥鍝勄庢潏顐熷亾閺囨氨鐟╁☉鎾翠亢椤曡櫕娼忛崨顓у殼20妤犵偠鎻槐婵嬪箑閼姐倗娉㈠ù婊冩缁夊鈧湱鍋熼弫銈夋儍閸曨剙鐦归悗瑙勭閺嗏偓闁哄鍔栭悡锛勬嫚閵忊剝鐓欐繛澶嬫礀瀵攱寰勫鍕槑闁哄倽顫夌涵鍫曟晬鐏炵偓绠掗梻鍥e亾閻熸洑鑳跺▓鎴︽儑鐎n厾绠栭柡澶涙嫹
 

//************************
//*        5_7.chh       *
//*      0.739085        *
//************************
# include <iostream.h>
# include <math.h>
double f();
void main()
{
        double m;
        m=f();
        cout<<"f(1e-6)[cos(x)=x]:="<<m<<endl;
}
double f()
{
        double f1=3.14159/4,f0=0;
        const double exp=1e-6;
        while (fabs(f1-f0)>exp)
        {
                f0=f1;
                f1=f0+(cos(f0)-f0)/(sin(f0)+1);
        }
        return f1;
}

//************************
//*        5_8.chh       *
//*                      *
//************************
# include <iostream.h>
# include <math.h>
void display(double);
void display(int);
void display(char);
void main()
{
        double m=2.0;
        display(m);
        float n=2.0;
        display(n);/*转换为double型*/
        int o=2;
        display(o);
        char p='a';
        display(p);
        short q=2;
        display(q);/*转换为int型*/
}
void display(double a)
{
        cout<<"A double:"<<a<<endl;
}
void display(int b)
{
        cout<<"A int:"<<b<<endl;
}
void display(char c)
{
        cout<<"A char:"<<c<<endl;
}

//************************
//*        5_9.chh       *
//*                      *
//************************
# include <iostream.h>
# include <math.h>
# include <iomanip.h>

int total(int a);
void main()
{
        int n,m;
        cout<<"please input years:"<<endl;
        cin>>n;

        m=total(n);
        cout<<"the total of cows:"<<m<<endl;
}
int total(int a)
{
        if (a<4)
                return 1;
        else
                return 2*total(a-4);

第六章

6.1
(1)
files2.cpp中的int fun();应为extern int fun()
files3.cpp中的extern int x=2;应为extern int x;
files3.cpp中的int g();应为extern g();
(2)
files2.cpp中y的声明类型和files1.cpp中的不一致
files1.cpp和files2.cpp中的extern int z;必须有一个为定义,即为int z;

6.2
输出结果为:25

6.3
//myhead.h
//all.cpp
//up.cpp
//down.cpp
//main.cpp

 

//************************
//*        myhead.h      *
//*                      *
//************************
# include <iostream.h>
# include <math.h>
# include <iomanip.h>
void all();
void down();
void up();

 

//************************
//*        all.cpp       *
//*                      *
//************************
# include "myhead.h"
void all()
{
        cout<<setw(6)<<setiosflags(ios::right)<<"*";
        int i;
        for (i=1;i<10;i++)
        {
                cout<<setw(6)<<setiosflags(ios::right)<<i;
        }
cout<<endl;
        for (i=1;i<11;i++)
        {
                cout<<setw(6)<<setiosflags(ios::right)<<".......";
        }
cout<<endl;

        for (i=1;i<10;i++)
        {
                cout<<setw(6)<<setiosflags(ios::right)<<i;
                int j;
                for (j=1;j<10;j++)
                {
                        cout<<setw(6)<<setiosflags(ios::right)<<i*j;
                }
                cout<<endl;
        }
        return;
}

 

//************************
//*        down.cpp      *
//*                      *
//************************
# include "myhead.h"
void down()
{
        cout<<setw(6)<<setiosflags(ios::right)<<"*";
        int i;
        for (i=1;i<10;i++)
        {
                cout<<setw(6)<<setiosflags(ios::right)<<i;
        }
cout<<endl;
        for (i=1;i<11;i++)
        {
                cout<<setw(6)<<setiosflags(ios::right)<<".......";
        }
cout<<endl;

        for (i=1;i<10;i++)
        {
                cout<<setw(6)<<setiosflags(ios::right)<<i;
                int j;
                for (j=1;j<i+1;j++)
                {
                        cout<<setw(6)<<setiosflags(ios::right)<<i*j;
                }
                cout<<endl;
        }
        return;
}

濞戞挴鍋撻柡澶樺灠閵堝爼鎳犻崜浣圭暠闂佽棄宕銊╁矗椤栨瑤绨板☉鏃€婢橀崺宀勬嚀閸愵亞鍩″☉鎾存尫缁楃喓鎷犻幑鎰偒闁哄倹鐟辩槐锟�
2濞戞挸娲ㄩ~鎺楁嚀閸愵亞鍩¢柣銏ゆ涧閻℃瑦绋婇敂鑲╃濡増锚缁ㄩ亶濡存担绛嬫綊濡増鍨埀顑跨閸欏繑绺藉Δ鍕偒闁哄倹鐟辩槐姘跺矗婵犲倸鍧婃鐐差嚟濠€鈩冿紣濮楀牏绀夋繛鎴犳暩濞诧拷547闁圭鍋撻梻鍕╁灪閻楋拷4濞戞挸娲g紞鎴炵▔椤忓洠鍋撻崘顏嗗煛闁兼澘鍟畷銉︾▔閹捐尙鐟圭紒澶嬪灩濞蹭即濡存担瑙e亾閸愵亞鍩¢柛蹇e墮閸欙紕鎷犻幘鍛闁衡偓閹稿簼绗夐柤鏄忕簿椤曘垽寮弶娆惧妳闁挎稑顦埀顒婃嫹40缂佸绉崇粭鎾寸▔濮橀硸鏁嬪璇″亾缁辨瑩鏌岄幋锝団偓铏规兜閺囩儑绱滈柕鍡曞簻BA闁靛棔绀佸ù妤呮⒔閸涱厽娅岄柛鏃撶磿椤㈡碍绔熼鐘亾娴h鐓€闂傚倽顔婄槐鍫曞箻椤撶媭鏁嬪璇″亖閳ь兛鑳堕妵鐐村濮橆兛绱eù锝嗙矌椤㈡碍绔熼銈囨惣闁挎稑顦埀顒婃嫹28缂侇偉顕ч幃鎾剁驳婢跺⿴鍔呴柛鏃€绋撻弫鐢垫兜閺囨氨鐟╁☉鎾村搸閳ь剨鎷�1130缂佸绉剁划锟犲礂閸涘﹥娈岄柡澶嬪姂閳ь剨鎷�

相关话题/

  • 领限时大额优惠券,享本站正版考研考试资料!
    大额优惠券
    优惠券领取后72小时内有效,10万种最新考研考试考证类电子打印资料任你选。涵盖全国500余所院校考研专业课、200多种职业资格考试、1100多种经典教材,产品类型包含电子书、题库、全套资料以及视频,无论您是考研复习、考证刷题,还是考前冲刺等,不同类型的产品可满足您学习上的不同需求。 ...
    本站小编 Free壹佰分学习网 2022-09-19