• <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>

            DraculaW

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              19 隨筆 :: 0 文章 :: 7 評(píng)論 :: 0 Trackbacks
            Assessing Infection

            Background

            According to the World Health Organization, infectious disease ranks as the leading cause of death in the world. In 1998 alone, over 17 million people died from infectious and parasitic diseases such as acute lower respiratory infections, tuberculosis, HIV/AIDS, and malaria. It is forecast that infectious disease will continue to kill millions of people, especially those living in developing countries.

            The medical profession and scientific community of the world are fighting the infectious disease threat with new tools and technologies from a variety of fields. From this effort, a new field of research has emerged. Infectious Disease Epidemiology is the study of the variables that influence the growth and spread of infectious diseases. This relatively new field combines molecular biology, immunology, genetics, and the computational sciences. A focus of this field is the study of the factors that influence the growth of an infectious disease within a single organism, and the factors that influence the pattern of infection across an entire population.

            Description

            This assignment asks you to finish the implementation of a program that assesses the level of infection in a tissue sample. You are given data representing a rectangular tissue sample, overlaid with a grid. Certain portions of the tissue are infected; others are not. Your goal is to help assess the extent of the infection by writing a program that, given the coordinates of a colony of infection, can determine its size.

            A typical use of the program follows. The user interacts with the program only through command-line arguments. The user supplies to the program a data filename and the coordinates of a cell in the grid. The coordinates are specified by row and then column, both starting at zero. The program calculates the extent of infection at that coordinate and outputs a two-dimensional representation of the tissue sample. Figure 1 depicts the execution of the program.

            A screen shot from a sample solution
            Figure 1 Output from a sample solution

            For the purpose of this assessment, we consider a "colony" of infected tissue to be a set of adjacent and infected cells. In Figure 1, we can see three separate colonies. The smallest colony consists of two cells and is located in the lower left corner of the grid. Another colony consisting of three infected cells exists on the far right edge of the grid. The largest colony of eight cells resides primarily in the middle of the grid. This colony has a small arm into the upper left corner of the grid. Notice from this colony that cells residing in diagonals are considered "adjacent." The plus signs next to the cells in this largest colony indicate that they all belong to the colony that contains the user entered coordinate.


            solution :

            #ifndef GRID_H
            #define GRID_H

            #include <string>
            #include <vector>

            using namespace std;

            /*
            * IMPORTANT NOTE:
            *
            * For this assignment, you might need to add state to the
            * class and/or augment existing methods, and/or create private helper
            * methods, but you should not delare new public methods
            */

            const bool INFECTED = true;
            const bool NOT_INFECTED = false;

            class grid;

            class grid {

            private:
                int rows;
                int cols;
                vector<bool> *area;
                vector<bool> *infect;
                int indexof (int row, int col) const;
                bool infected(int row, int col) const;

            public:
                grid (string file);
                ~grid ();

                int count (int row, int col);

                friend ostream &operator<<(ostream &stream, const grid& ob);

            };

            #endif

            ============================================================================

            #include <iostream>
            #include <fstream>

            using namespace std;

            #include "grid.h"

            // You do not need to alter function indexof.
            int grid::indexof (int row, int col) const {
                return row*cols+col;
            }

            // You do not need to alter function infected.
            bool grid::infected(int row, int col) const {
                return (area->operator[](indexof(row, col)) == INFECTED);
            }

            // You may need to alter the constructor
            grid::grid (string file) {

                ifstream grid_file;

                grid_file.open (file.c_str());

                grid_file >> rows;
                grid_file >> cols;

                area = new vector<bool>(rows*cols, NOT_INFECTED);
                infect = new vector<bool>(rows*cols, NOT_INFECTED);
               
                while (true) {

                    int blob_row;
                    int blob_col;

                    grid_file >> blob_row;
                    grid_file >> blob_col;

                    if (grid_file.eof()) {
                        break;
                    }

                    area->operator[](indexof(blob_row,blob_col)) = INFECTED;
                }

                grid_file.close();
            }

            // You may need to alter the destructor
            grid::~grid () {
                delete area;
                delete infect;
            }

            // You will need to alter this function to display the
            // plus signs (+) next to the cells that belong to
            // a counted colony.
            ostream &operator<<(ostream &stream, const grid& ob) {

                for (int row=0; row < ob.rows; row++) {
               
                    for (int col=0; col < ob.cols; col++) {

                        stream << ob.area->operator[](ob.indexof(row, col));
                        if( ob.infect->operator[] ( ob.indexof(row, col) ) )
                            stream << "+ ";
                        else
                            stream << "   ";
                    }

                    stream << endl;
                }

                stream << endl;
                return stream;
            }

            // Replace the return statement in this function with your
            // recursive implementation of this method */
            int grid::count (int row, int col) {

                if( row < 0 || col < 0 || row == rows || col == cols)
                    return 0;

                if( area->operator[](indexof(row,col) ) == NOT_INFECTED )
                    return 0;

                if(infect->operator[](indexof(row,col)) == INFECTED)
                    return 0;

                infect->operator[](indexof(row,col)) = INFECTED;

                // Recursive test the 8 point near the point
                // which area is INEFCTED and infect is NOT_INFECTED

                return    count( row - 1, col - 1 ) + count ( row - 1, col )
                    + count( row - 1, col + 1 ) + count( row, col - 1 )
                    + count( row, col ) + 1 + count( row, col + 1 )
                    + count( row + 1, col - 1 ) + count( row + 1, col )
                    + count( row + 1, col + 1 );
            }
            posted on 2007-11-15 20:40 DraculaW 閱讀(484) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            久久精品国内一区二区三区 | 国产精品久久午夜夜伦鲁鲁| 亚洲欧洲久久久精品| 久久久噜噜噜久久中文字幕色伊伊 | 国产精品一区二区久久国产| 热久久这里只有精品| 久久99精品久久久久久齐齐| 久久久久久久波多野结衣高潮| 久久婷婷五月综合色高清| 精品国产乱码久久久久久1区2区 | 99久久夜色精品国产网站 | 色99久久久久高潮综合影院 | 亚洲精品高清国产一线久久| 国产成人精品免费久久久久| 久久精品这里只有精99品| 亚洲国产精品久久久天堂| 久久五月精品中文字幕| 国产精品一久久香蕉国产线看| 久久乐国产精品亚洲综合| 国产精品久久午夜夜伦鲁鲁| 大香伊人久久精品一区二区| 日本三级久久网| 99久久无码一区人妻a黑| 波多野结衣久久一区二区 | 欧美久久久久久精选9999| 777米奇久久最新地址| 亚洲精品国产字幕久久不卡| 欧美国产精品久久高清| 999久久久免费国产精品播放| 97久久超碰国产精品2021| 色婷婷久久综合中文久久蜜桃av| 一级做a爰片久久毛片看看| A级毛片无码久久精品免费| www久久久天天com| AV无码久久久久不卡蜜桃| 韩国无遮挡三级久久| 精品永久久福利一区二区| 久久精品国产网红主播| 久久精品中文字幕无码绿巨人| 久久精品国产亚洲AV麻豆网站| 亚洲综合精品香蕉久久网|