• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              117 Posts :: 2 Stories :: 61 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(8)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜


            第一個(gè)程序:      
            #include "stdafx.h"
            #include 
            <iostream>
            using namespace std;
            struct travel_time
            {
                
            int hours;
                
            int mines;
            }
            ;
            const int Mines_per_hr = 60;
            travel_time sum(travel_time t1, travel_time t2);
            void show_time(travel_time t);
            int main(int argc, char* argv[])
            {
                travel_time day1 
            = {545}
                travel_time day2 
            = {455};
                travel_time trip 
            = sum (day1, day2);
                cout
            <<"Two-day total: ";
                show_time(trip);
                
                travel_time day3
            ={4,32};
                cout
            <<"Three-day total: ";
                show_time(sum(trip,day3));
                
            return 0;
            }

            travel_time sum(travel_time t1, travel_time t2)
            {
                travel_time total;
                total.mines
            =(t1.mines+t2.mines)%Mines_per_hr;
                total.hours
            =t1.hours+t2.hours+(t1.mines+t2.mines)/Mines_per_hr;
                
            return total;
            }

            void show_time(travel_time t)
            {
                cout
            <<t.hours<<" hours, "<<t.mines<<" minutes\n";
            }

            第二個(gè)程序:
                  這個(gè)例子將定義兩個(gè)結(jié)構(gòu),用于表示兩種不同的描述位置的方法,然后開(kāi)發(fā)一個(gè)函數(shù),將一種格式轉(zhuǎn)換為另一種格式,并顯示結(jié)果。
            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <cmath>
            using namespace std;
            //structure declarations
            struct polar
            {
                
            double distance;    //distance from origin
                double angle;        //direction from origin
            }
            ;
            struct rect
            {
                
            double x;        //horizontal distance from origin
                double y;        //vertical distance from origin
            }
            ;

            // prototypes
            polar rect_to_polar(rect xypos);
            void show_polar(polar dapos);
            int main(int argc, char* argv[])
            {
                rect rplace;
                polar pplace;
                cout
            <<"Enter the x and y values: ";
                
            // 將cin>>用作測(cè)試條件消除了這種限制,因?yàn)樗邮苋魏斡行У財(cái)?shù)字輸入。
                
            // 在需要使用循環(huán)來(lái)輸入數(shù)字時(shí)候,別忘了考慮使用這種方式。另外請(qǐng)記住,
                
            // 非數(shù)字輸入將設(shè)置一個(gè)錯(cuò)誤條件,禁止進(jìn)一步讀取輸入。如果程序在輸入
                
            // 循環(huán)后還需要進(jìn)行輸入,則必須使用cin.clear()重置輸入,然后可能需
                
            // 要通過(guò)讀取不合法的輸入來(lái)丟棄它們。
                while(cin>>rplace.x>>rplace.y)    //slick use of cin
                {
                    pplace 
            = rect_to_polar(rplace);
                    show_polar(pplace);
                    cout
            <<"Next two numbers(q to quit): ";
                }

                cout
            <<"Done.\n";
                
            return 0;
            }


            //convert rectangular to polar coordinates
            polar rect_to_polar(rect xypos)
            {
                polar answer;
                answer.distance
            =sqrt(xypos.x * xypos.x + xypos.y * xypos.y);
                answer.angle
            =atan2(xypos.y, xypos.x);
                
            return answer;    
            }

            //show polar coordinates, converting angle to degrees
            void show_polar(polar dapos)
            {
                
            const double Rad_to_deg=57.29577951;
                cout
            <<"distance = "<<dapos.distance;
                cout
            <<", angle = "<<dapos.angle * Rad_to_deg;
                cout
            <<" degrees\n";
            }

            第三個(gè)程序
                  傳遞結(jié)構(gòu)的地址。假設(shè)要傳遞結(jié)構(gòu)的地址而不是整個(gè)結(jié)構(gòu)以節(jié)省時(shí)間和空間,則需要重新編寫前面的函數(shù),使用指向結(jié)構(gòu)的指針。對(duì)于重新編寫show_polar()函數(shù),需要修改3個(gè)地方:1、調(diào)用函數(shù)時(shí),將結(jié)構(gòu)的地址(&pplace)而不是結(jié)構(gòu)本身(pplace)傳遞給它。2、將形參聲明為指向polar的指針,即polar*類型。由于函數(shù)不應(yīng)該修改結(jié)構(gòu),因此使用const修飾。3、由于形參是指針而不是結(jié)構(gòu),因此應(yīng)使用間接成員操作符(->),而不是成員操作符(句點(diǎn))。
            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <cmath>
            using namespace std;
            //structure declarations
            struct polar
            {
                
            double distance;    //distance from origin
                double angle;        //direction from origin
            }
            ;
            struct rect
            {
                
            double x;        //horizontal distance from origin
                double y;        //vertical distance from origin
            }
            ;

            // prototypes
            void rect_to_polar(const rect* pxy, polar* pda);
            void show_polar(const polar *pda);
            int main(int argc, char* argv[])
            {
                rect rplace;
                polar pplace;
                cout
            <<"Enter the x and y values: ";
                
            while(cin>>rplace.x>>rplace.y)    //slick use of cin
                {
                    rect_to_polar(
            &rplace, &pplace);
                    show_polar(
            &pplace);
                    cout
            <<"Next two numbers(q to quit): ";
                }

                cout
            <<"Done.\n";
                
            return 0;
            }

            void rect_to_polar(const rect* pxy, polar* pda)
            {
                pda
            ->distance=sqrt(pxy->* pxy->+ pxy->* pxy->y);
                pda
            ->angle=atan2(pxy->y, pxy->x);
            }

            void show_polar(const polar *pda)
            {
                
            const double Rad_to_deg=57.29577951;
                cout
            <<"distance = "<<pda->distance;
                cout
            <<", angle = "<<pda->angle * Rad_to_deg;
                cout
            <<" degrees\n";
            }
            posted on 2010-02-12 19:02 煙皚 閱讀(357) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++ primer plus學(xué)習(xí)筆記
            国产午夜精品理论片久久影视| 一级做a爰片久久毛片毛片| 国产69精品久久久久9999| 久久精品国产亚洲av麻豆色欲 | 狼狼综合久久久久综合网| 久久亚洲国产精品123区| 99久久国产免费福利| 91久久精品国产91性色也| 91精品国产综合久久久久久| 久久精品九九亚洲精品| 久久综合香蕉国产蜜臀AV| 亚洲国产精品久久电影欧美| 久久综合88熟人妻| 91久久婷婷国产综合精品青草| 91久久精一区二区三区大全| 嫩草影院久久国产精品| 国产精品免费久久| 少妇久久久久久被弄到高潮 | 99国产欧美精品久久久蜜芽| 久久综合久久自在自线精品自| 97热久久免费频精品99| 久久久综合九色合综国产| 亚洲欧洲久久久精品| 亚洲中文字幕无码久久精品1| 一本色综合网久久| 国产精品久久久久9999| 久久久久婷婷| 久久亚洲精品人成综合网| 久久九九青青国产精品| 老司机午夜网站国内精品久久久久久久久 | 久久久久九九精品影院| 国产精品久久久香蕉| 婷婷久久久亚洲欧洲日产国码AV| 久久国产精品99久久久久久老狼| 久久国产热这里只有精品| 亚洲中文久久精品无码ww16| 2022年国产精品久久久久| 色婷婷久久久SWAG精品| 国产麻豆精品久久一二三| 亚洲国产精品成人久久蜜臀| 国产精品岛国久久久久|