青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

DraculaW

  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
  19 隨筆 :: 0 文章 :: 7 評論 :: 0 Trackbacks

Calculating "The Sum of Its Parts"


Background

"The whole is greater than the sum of its parts" is a central theme of Gestalt psychology, and for humans it may be a true observation. Computers are much more literal-minded.

Description

In this assessment, you will construct a representation of a complex structure, a hospital that is composed of many parts. There are too many parts for a human to keep track of, which is why we want the computer to do it for us. The description of the hospital is contained in the file definitions.txt.


picture of a top-level view of a hospital floor
Figure 1 Layout of a floor in the hospital

The building has ten floors. Each floor has four wings emanating from a central core.

Each wing contains two long corridors joined at the end by a short connecting corridor.

Each long corridor contains twenty-one patient rooms. Each connecting corridor contains five supply rooms.

The hospital is described by a labeled tree, whose nodes are of type Part. A node contains children nodes corresponding to its subparts, as shown in the figure below. Each edge is labeled by the number of subparts the node contains. For example, the label 10 on the edge from hospital to floor indicates that the hospital has ten floors. You can assume there are no duplicate edges, that is, there is at most one edge between any two nodes.


tree representation of the parts in a hospital
Figure 2 Tree representation of the hospital

The driver program main.cpp first loads the file definitions.txt, which contains the subpart relationships that define the hospital. It then processes queries from the file queries.txt, which contains two kinds of queries about the hospital. The whatis query requests the description of a Part. The howmany query is the heart of the exercise. It asks how many instances of a Part are contained in another Part.

You are provided with main.cpp and a skeleton version of parts.h as a starting point. Your job is to complete the parts.h file (and write parts.cpp, if you deem necessary). The steps below point the way toward a solution, but they do not cover every detail, so if you find you need to create additional functions or member items, feel free to do so.





#ifndef _PARTS_H_
#define _PARTS_H_

#include <vector>
#include <map>
#include <string>

using namespace std;

//**************** Part ****************
class Part {
   
public:
    string name;

    map<Part*, int> subparts;
   
    Part(string const &n) : name(n) {};
    void describe(void);
    int count_howmany(Part const *p);
};


//**************** NameContainer ****************
class NameContainer {

private:
    map<string,Part*> name_map;

public:

    NameContainer(void) {};

    Part* lookup(string const &name) {

        for( map<string, Part*>::iterator it = name_map.begin();
             it != name_map.end(); it++ )
        {
            if( it->first == name )
                return it->second;
        }
        Part *new_part = new Part( name );
        name_map[name] = new_part;
        return name_map[name];
    }
};

NameContainer partContainer;

//**************** Part Member Functions ****************
void Part::describe(void) {
   
    cout << "Part " << name << "subparts are" << endl;

    if( subparts.empty())
    {
        cout << " There no subparts" << endl;
        return;
    }
       

    for( map<Part*, int>::iterator it = subparts.begin();
         it != subparts.end(); it++ )
    {
        cout << " " << it->second << " " << it->first->name << endl;
    }

    cout << endl;
}

int Part::count_howmany(Part const *p) {
       
    if( this->name == p->name ) return 1;

    if( this->subparts.empty() )return 0;

    int sum = 0;

    for( map<Part*, int>::iterator it = subparts.begin();
         it != subparts.end(); it++ )
    {
        sum += ( ( it->second ) * ( it->first->count_howmany( p )) );
    }

    return sum;
}

//**************** Miscellaneous Functions ****************
void add_part(string const &x, int q, string const &y) {

    // TODO: Finish implementation
    Part *parent = partContainer.lookup(x);
    Part *child = partContainer.lookup(y);

    parent->subparts.insert( make_pair( child, q ) );
}

#endif

posted on 2007-11-15 20:39 DraculaW 閱讀(460) 評論(0)  編輯 收藏 引用
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美香蕉视频| 一区二区免费在线观看| 亚洲精品九九| 91久久午夜| 欧美视频在线一区二区三区| 欧美一区二区三区四区视频| 亚洲黄色在线看| 欧美一区三区三区高中清蜜桃| 国产日韩欧美二区| 欧美黑人在线观看| 欧美一区亚洲二区| 91久久夜色精品国产网站| 久久久久久成人| 99re6这里只有精品| 国产精品国产三级国产aⅴ9色| 国产精品久久久久秋霞鲁丝| 韩国三级在线一区| aa级大片欧美| 久久精品99国产精品| 欧美va亚洲va香蕉在线| 亚洲精品一级| 久久久精品国产免费观看同学| 免费国产一区二区| 国产精品成人一区二区三区夜夜夜 | 欧美激情久久久| 亚洲美女在线观看| 欧美一区成人| 欧美日本三级| 久久蜜桃精品| 99国产精品国产精品久久| 亚洲性感美女99在线| 久久亚洲二区| 日韩亚洲一区二区| 久久久久久69| 国产精品乱码妇女bbbb| 亚洲激情国产精品| 久久疯狂做爰流白浆xx| 亚洲三级影院| 久久久精彩视频| 国产精品爽爽爽| 亚洲精品一区中文| 久久久欧美精品| 亚洲一线二线三线久久久| 欧美大香线蕉线伊人久久国产精品| 国产精品v欧美精品v日韩 | 亚洲国产高清在线观看视频| 亚洲尤物在线| 亚洲欧洲精品一区二区三区波多野1战4| 亚洲欧美久久| 欧美性色视频在线| 日韩午夜在线播放| 欧美高清视频一区| 久久成人免费网| 国产伦精品一区二区| 一区二区三欧美| 亚洲国产你懂的| 久久精品日产第一区二区| 国产精品尤物| 亚洲欧美另类久久久精品2019| 亚洲精品视频在线| 欧美区视频在线观看| 亚洲精品一区二区三区樱花 | 欧美福利视频在线| 亚洲电影av在线| 久久久久久伊人| 亚洲欧美日韩国产综合| 国产精品h在线观看| 亚洲丝袜av一区| 亚洲美女免费精品视频在线观看| 欧美精品精品一区| 亚洲制服欧美中文字幕中文字幕| 99re视频这里只有精品| 国产精品va| 欧美一区二视频在线免费观看| 这里只有精品电影| 欧美日韩精品二区| 午夜精品一区二区三区在线 | av不卡免费看| 99精品欧美一区| 欧美午夜国产| 午夜在线一区二区| 久久av红桃一区二区小说| 99精品视频免费| 9国产精品视频| 国产日本欧美一区二区三区在线| 午夜欧美精品| 亚洲欧美清纯在线制服| 韩国成人理伦片免费播放| 欧美大片在线看免费观看| 欧美理论电影在线播放| 西瓜成人精品人成网站| 久久综合999| 亚洲午夜精品久久久久久app| 亚洲欧美日韩综合| 亚洲国产精品www| 亚洲视频一二| 亚洲国产精品毛片| 亚洲视频在线看| 在线播放日韩欧美| 日韩一级网站| 韩国av一区二区| 亚洲精品裸体| 国产一区视频在线看| 亚洲精品看片| 一区二区三区在线视频免费观看| 亚洲伦理在线观看| 国产午夜精品久久| 99av国产精品欲麻豆| 在线播放日韩专区| 亚洲欧洲日韩女同| 亚洲欧美国产一区二区三区| 亚洲精品国产精品国自产观看| 99视频热这里只有精品免费| 禁久久精品乱码| 亚洲视频一区二区免费在线观看| 在线精品国精品国产尤物884a| 亚洲四色影视在线观看| 亚洲精品视频免费在线观看| 欧美在线观看视频在线| 亚洲一区欧美激情| 欧美激情网友自拍| 欧美xx视频| 韩国福利一区| 亚洲欧美日韩在线高清直播| 亚洲图片欧洲图片日韩av| 欧美 日韩 国产精品免费观看| 久久激情视频免费观看| 免费人成精品欧美精品| 国产精品日日做人人爱| 亚洲毛片播放| 日韩视频免费大全中文字幕| 久久综合伊人77777蜜臀| 久久久久一本一区二区青青蜜月| 国产精品草草| 一区二区日本视频| 99精品视频免费观看视频| 欧美激情bt| 亚洲精品免费在线观看| 日韩视频在线免费观看| 欧美激情影院| 日韩午夜在线| 亚洲亚洲精品三区日韩精品在线视频| 欧美xxx成人| 欧美黄色一区| 日韩亚洲视频| 欧美日韩大陆在线| 一区二区三区成人精品| 亚洲天堂av图片| 亚洲黄色av一区| 日韩一级黄色大片| 亚洲一区在线免费观看| 欧美午夜视频一区二区| 欧美—级a级欧美特级ar全黄| 精品不卡在线| 久久久久久9| 蜜臀a∨国产成人精品| 欧美揉bbbbb揉bbbbb| 日韩午夜在线视频| 欧美在线看片a免费观看| 国产亚洲一区精品| 久久er精品视频| 免费久久精品视频| 亚洲韩国日本中文字幕| 欧美日本免费| 亚洲欧美成人网| 久久久精品2019中文字幕神马| 国产亚洲制服色| 久久久久国色av免费看影院| 亚洲全部视频| 久久gogo国模裸体人体| 亚洲美女免费视频| 国产日韩欧美不卡| 欧美国产日韩a欧美在线观看| 亚洲午夜影视影院在线观看| 免费久久精品视频| 性色一区二区三区| 亚洲精品国产拍免费91在线| 国产精品丝袜白浆摸在线| 久久夜色精品国产噜噜av| 一区二区三区日韩欧美| 欧美高清在线精品一区| 欧美一级黄色录像| 日韩视频一区二区在线观看 | 理论片一区二区在线| 亚洲日本一区二区| 国产欧美日韩不卡免费| 嫩草国产精品入口| 欧美在线91| 亚洲一区二区三区精品在线| 欧美激情1区| 久久这里只有| 欧美在线短视频| 这里只有视频精品| 亚洲欧洲综合另类| 影音先锋中文字幕一区二区| 国产精品爽黄69| 欧美日韩综合在线| 欧美顶级艳妇交换群宴| 久久婷婷国产麻豆91天堂| 欧美一级视频免费在线观看|