Question

In: Computer Science

Nobody wants a nuclear power plant in their neighborhood. Unfortunately, the governor must locate a nuclear...

Nobody wants a nuclear power plant in their neighborhood. Unfortunately,

the governor must locate a nuclear power plant somewhere inside a 25 square

mile area containing four cities. The governor, being primarily concerned

with reelection, desires to locate the plant in the location which will

cause the least amount of unhappiness among the constituents. In this lab,

you will write a program to assist the governor in this difficult decision.

METHOD:

^^^^^^^

Assume each city is located in an integer-pair (x, y) valued location

within a 25 x 25 square mile area. For example, a city can be located at

(4, 19), but not at (4.5, 19.8). In other words, there are no real valued

coordinate for a location of a city.

Your program will consider each integer-pair valued location within the area

as a possible site for the nuclear plant, starting at (1, 1) and continuing

across each row until the final site (25, 25) is reached.

At each possible location for the nuclear plant, your program will compute

the average unhappiness if the plant were located there. The following two

rules will be used to compute the unhappiness for a city.

      1) If the plant is within two miles or less of a city, the

         unhappiness is infinite (that is, assign a very large number

                   to the unhappiness for that city).

                   2) Otherwise, the unhappiness is equal to the population of the

                      city divided by the distance of the plant from the city.

                      The average unhappiness equals:

                     

                               Avg. Unhappiness = Sum of the unhappiness of 4 cities /

                                                                   The total state's population.

Your program should select the site at which the average unhappiness is

smallest.

INPUT:

^^^^^^

The user should be prompted to enter the x and y coordinates and the

population for each of the four cities from the keyboard. Each coordinate

should be checked to ensure it is between 1 and 25. If not, the user should

be prompted to enter a value which is in the correct range. The population

should be entered in thousands of people. For example, if the population

is 10,000, the user should input 10.

OUTPUT:

^^^^^^^

The program should print a message indication the coordinates where

the plant should be located. Following that message, the user should be

prompted to enter a 1 to view a map of the scenario or a 0 to exit the

program.

An Example Scenario:

Enter the x and y for City 1   : 1 1

Enter the Population for City 1: 10

Enter the x and y for City 2   : 1 25

Enter the Population for City 2: 10

Enter the x and y for City 3   : 25 1

Enter the Population for City 3: 10

Enter the x and y for City 4   : 25 25

Enter the Population for City 4: 10

**********

Locate the Plant At: 13 13

Enter 1 to view a Map of the scenario, or 0 to exit: 1

               MAP OF SCENARIO

                   ---------------   

C2<><><><><><><><><><><><><><><><><><><><><><><>C4

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><>PP<><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

<><><><><><><><><><><><><><><><><><><><><><><><><>

C1<><><><><><><><><><><><><><><><><><><><><><><>C3

Note: The previous scenario is just an example, you need to create your own

test cases to make sure that your program produces the correct results.

Solutions

Expert Solution

The code is well explained in the comments. The screenshots of the codes are here for better understanding.

The output of the above code is:

I am attaching the code with comments for understanding So that manipulation of code could e possible for further requirements.

#include<bits/stdc++.h>
using namespace std;

int main() {

   int arr[25][25] ={0}; //declaring an array where i,j is the location of the city
   int n;
   cout<<"Enter the number of cities"<<endl;
   cin>>n; // where n is number of cities
   for(int i=0; i<n; i++)
   {
       int x,y,z;
       cout<<"Enter the x and y for City "<<i+1<<": "<<endl;
       cin>>x>>y;

        cout<<"Enter the Population for City "<<i+1<<": "<<endl;
       cin>>z;
if((x < 1) || (x > 25) || (y < 1) || (y > 25)) // if the city is not in the range then input again
   {
       cout<<"Enter a value which is in the correct range"<<endl;
       i--;
   }
       else arr[x-1][y-1]=z; // storing the population at the location

   }

   int x1,y1;
   cout<<"Locate the Plant At: "<<endl;
   cin>>x1>>y1;
while((x1 < 1) || (x1 > 25) || (y1 < 1) || (y1 > 25)) // if the plant is not in the range then input again
   {
       cout<<"Enter a value which is in the correct range"<<endl;
       cout<<"Locate the Plant At: "<<endl;
           cin>>x1>>y1;
      
}


double un = 0; // declaring the variable which will tell about total unhapppiness in te city
int flag = 0; // for checking if the city is within 2 miles
int sum = 0; // sum is storingt the total population of the state
for(int i=0;i<25;i++)
{
   for(int j=0;j<25;j++)
   {
       if(arr[i][j] > 0)
       {
           int v = (i+1-x1)*(i+1-x1);
           int b = (j+1-y1)*(j+1-y1);
cout<<v<<" "<<b<<endl;
           double dis = sqrt(v+b); // finding the distance
          
           if(dis > 2) un = un + (arr[i][j]/dis);
           else flag = 1;
           cout<<un<<endl;
           sum = sum + arr[i][j]; // sum is storingt the total population of the state
       }
   }
}
  
if(flag == 1) un = 1000000.00/sum;
else un = un / sum;

cout<<"Avg. Unhappiness: "<<un<<endl;


// printing the map


cout<<"Enter 1 to view a Map of the scenario, or 0 to exit: "<<endl;
int m;
cin>>m;
if(m == 1)
{
   for(int i=0;i<25;i++)
       {
           for(int j=0;j<25;j++)
           {
               if(arr[i][j] > 0)
               {
                   cout<<"City";
               }
               else if(i == x1-1 && j== y1-1) cout<<"PP";
               else cout<<"<>";
           }
           cout<<endl;
       }
}

   return 0;
   }



Related Solutions

Governor John has decided that, rather than build a new nuclear power plant to service power...
Governor John has decided that, rather than build a new nuclear power plant to service power needs, the state should save an equivalent amount of energy. As one component of an efficiency plan, he has turned to you, his top aide, to design a policy to encourage adoption of compact fluorescent (CF) lightbulbs. Although CFs save a tremendous amount of money (and energy) over their lifetime, they are quite expensive initially ($20 or so per bulb in 1993). In addition,...
Label the components of a nuclear power plant
 Label the components of a nuclear power plant A 462.5 ng sample of an unknown radioactive substance was placed in storage and its mass measured periodically. After 47 days the amount of radioactive substance had decreased to 57.81 ng. How many half-lives of the unknown radioactive substance have occurred? Sodium-24, which is used to locate blood clots in the human circulatory system, has a half-life of 15.0 h. A sample of sodium-24 with an inital mass of 24.5 g was stored for...
A neighborhood fuel cell power plant is to be designed for an electric power output of...
A neighborhood fuel cell power plant is to be designed for an electric power output of 2000 kW with liquid– water product. Estimate the flow rates of hydrogen and oxygen during peak power production, assuming an 80% efficient power conditioner is used to convert DC to AC power and the fuel cell efficiency is 55%. What is the plant heat rate?
A nuclear power plant is planned to be constructed near Sydney. The plant is required to...
A nuclear power plant is planned to be constructed near Sydney. The plant is required to have an installed capacity of 1200 MW and will be operated for 7500 hours per year. Consider providing 1200 MW of energy by two solar power plants; one in Sydney and the other in Canberra. It is required that a fixed solar module be mounted. Determine the following parameters if the overall efficiency of the module is given as 15%: a) The peak power...
A nuclear power plant has an overall efficiency of 31% and a power output of 800MW....
A nuclear power plant has an overall efficiency of 31% and a power output of 800MW. For one year operating at full capacity, calculate a) the number of joules produced; b) the number of fission events that were required to produce those joules; c) the mass of uranium oxide (UO2) that has been used in fission; and d) the market cost of that uranium oxide if it was all high quality.
Consolidated Power, a large electric power utility, has just built a modern nuclear power plant. This...
Consolidated Power, a large electric power utility, has just built a modern nuclear power plant. This plant discharges waste water that is allowed to flow into the Atlantic Ocean. The Environmental Protection Agency (EPA) has ordered that the waste water may not be excessively warm so that thermal pollution of the marine environment near the plant can be avoided. Because of this order, the waste water is allowed to cool in specially constructed ponds and is then released into the...
A disaster such as a meltdown in a nuclear power plant requires close examination of potential...
A disaster such as a meltdown in a nuclear power plant requires close examination of potential impacts on organisms. Which of the following would be useful to biologists in such a situation? Use a molecular clock to time the divergence of species in an area from those far away. Measure continental drift to determine if the disaster had accelerated movement of continents. Use radiometric dating to determine if new species are forming. Examine the mutation rate of species in the...
uranium-235 is used in a nuclear power plant as fuel source because
uranium-235 is used in a nuclear power plant as fuel source because
Mr. Burns is looking to open a second nuclear power plant in Springfield. It will have...
Mr. Burns is looking to open a second nuclear power plant in Springfield. It will have the following cash flows: Year Cash Flow 0   -29,000 1    11,200 2    13,900 3 15,800 4    12,000 5 -9,400 The company uses an 9% discount rate on all of its projects. Using the combination method what is the MIRR of the project?
What types of reactions occur in a nuclear power plant? Is the process endothermic or exothermic?...
What types of reactions occur in a nuclear power plant? Is the process endothermic or exothermic? Please answer in more than 150 words.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT