1 answer

INSTRUCTIONS 1. Prompt the user for the number of participating units and expected peak demand hours...

Question:

INSTRUCTIONS 1. Prompt the user for the number of participating units and expected peak demand hours 2. Create two arrays: OTHINK: Think about this for a minute. This requires repeated action to shut down the number of units needed to meet demand, srun: Enter the number of units: Enter the number of hours: In hour 1 we need to shut down 2 units: Unit 0 is OFF with creditsISIVI3230 In-class lab Module - Working with Arrays Spring 2020 FOCUS TOPICS • Arrays: storing multiple values of the same ty

INSTRUCTIONS 1. Prompt the user for the number of participating units and expected peak demand hours 2. Create two arrays: O A String array called unitstatus, with an array element count equal to the number of participating units o An int array called unitCredit, with an array element count equal to the number of participating units O HINT: make sure you understand the difference between array size (element count) and element index (position) 3. Initialize the arrays, setting each element of the unitStatus array to "ON", and each element of unitCredit to zero o THINK: Think about this for a minute. This requires repeated actions (since you want to do the same thing to each element of each array), so you'll need a loop. What type of loop would work best for this? A while loop or a for loop? 4. For now, work continue to work as if you are solving for a single hour of demand: Shut down the number of units needed to meet demand: To determine how many units to shut down, generate a random integer between 0 and the total number of A/C units . HINT: Be sure that your code allows for 0 units to be needed, as well as the maximum number of units available. For example, if there are 3 units available, then the set of possible values should be 0, 1, 2, and 3. Be sure to test this carefully! O Print the number of units to be shut down in this hour o Mark units as shut down (with credit), starting with the first unit and working sequentially through the array until you have turned off enough units.
THINK: Think about this for a minute. This requires repeated action to shut down the number of units needed to meet demand, so you'll need a loop. What type of loop would work best for this? A while loop or a for loop? Within the loop: 1. Set unit's status to "OFF" 2. Add a credit for the unit you just turned off 5. Next, document what happened during the demand hour o THINK: Think about this for a minute. This requires repeated action to print for each, so you'll need a loop. What type of loop would work best for this? A while loop or a for loop? THINK: This loop cannot be the same loop you used to shut down the A/C units, because you need to print the documentation for all units, not just the ones that need to be shut down. Therefore, this needs to be a separate loop. o Within the loop: Print the on/off status for each participating unit and the total credits the unit has accumulated . HINT: Print"\t" just before printing the number of credits to align them vertically • Ensure that each unit is "ON" again after crediting those that were off and printing the documentation. This can be done in the same loop as the printing, since it applies to all units At this point in the lab, your code should calculate results and print the documentation for a single hour. Stop and test carefully to make sure that your code is working correctly for a single hour. The next step is to make this work for multiple hours of expected peak demand. 6. Create a way to run your logic so that the same logic runs for each demand hour o THINK: Think about this for a minute. This requires repeated action, so you'll need a loop. What type of loop would work best for this? A while loop or a for loop? O THINK: Which logic stays above this loop? Which logic goes inside this loop? Which logic goes below this loop? 7. Make sure that your output matches the sample output in wording, capitalization, punctuation, and spacing
run: Enter the number of units: Enter the number of hours: In hour 1 we need to shut down 2 units: Unit 0 is OFF with credits: 1 Unit 1 is OFF with credits: 1 In hour 2 we need to shut down 0 units: Unit 0 is ON with credits: 1 Unit 1 is ON with credits: 1 In hour 3 we need to shut down 1 units: Unit 0 is OFF with credits: 2 Unit 1 is ON with credits: In hour 4 we need to shut down 0 units: Unit 0 is ON with credits: 2 Unit 1 is ON with credits: 1 In hour 5 we need to shut down 2 units: Unit 0 is OFF with credits: 3 Unit 1 is OFF with credits: 2 BUILD SUCCESSFUL (total time: 5 seconds) run: Enter the number of units: Enter the number of hours: In hour 1 we need to shut down 2 units: Unit 0 is OFF with credits: 1 Unit 1 is OFF with credits: 1 In hour 2 we need to shut down 0 units: Unit 0 is ON with credits: 1 Unit 1 is ON with credits: 1 In hour 3 we need to shut down 0 units: Unit 0 is ON with credits: 1 Unit 1 is ON with credits: 1 In hour 4 we need to shut down 1 units: Unit 0 is OFF with credits: 2 Unit 1 is ON with credits: 1 BUILD SUCCESSFUL (total time: 3 seconds)
ISIVI3230 In-class lab Module - Working with Arrays Spring 2020 FOCUS TOPICS • Arrays: storing multiple values of the same type Loops Random number generator TASK You are working for a utility company that provides electrical service to the local region. The company faces a serious problem: at times of high heat, high demand for electricity for air conditioning at times overwhelms available capacity, leading to power outages. To avoid this, the company has offered customers the option to have their air conditioner configured with remote control technology, and allow the company to shut down the A/C unit for an hour. In return, the customer receives a cost savings on the monthly bill for each hour the company turns off the A/C unit You have been asked to develop a prototype that: • For each demand hour: determines how many units need to be turned off, and tracks which units you have turned off Tracks credits for each hour an A/C unit is turned off, so that the corresponding customer can be credited at the end of the billing cycle The program should do the following: • Allow the user to enter the number of participating A/C units and the number of expected hours of peak demand Create and manage a set of data structures for keeping track of the status of A/C unit, and the number of credits earned for shut-off hours For each hour of peak demand: o Use random number generator to select the number of units the company needs to shut down to meet demand O Mark the status of turned-off units as "off" (note: for simplicity, always turn off units starting with unit 0 and going up) o Add a credit for each hour an A/C unit is shut down Print, for each hour of peak demand: o Number of unit-shutdowns needed to meet demand o The on/off status of each unit during the demand hour, and the total number of credits earned Ensure that each A/C unit is turned on at the end of each peak-demand hour • •

Answers

The answer will not be the same always because it is generating random integer. Do not panic if you don't get the same answer

#include <iostream>
using namespace std;

int main() {
   //no of participating units participating p
   //no of expected peak hours t
  
   int p,t;
   cin>>p>>t;
   cout<<"Enter the number of units:"<<endl;
   cout<<p<<endl;
   cout<<"Enter the number of hours:"<<endl;
   cout<<t<<endl;
   string Unitstatus[p];
   int Unitcredit[p];
   for(int i=0;i<p;i++)
   {
        Unitstatus[i]="ON";
        Unitcredit[i]=0;
   }
   //for every demand hour
   for(int i=1;i<=t;i++)
   {
        //generate random number between 0 and p
        int num = (rand() %(p - 0 + 1)) + 0;
        cout<<"In hour "<<i<<" we need to shut down "<<num<<" units:"<<endl;
        for(int j=0;j<num;j++)
        {   if(Unitstatus[j]=="OFF")
                Unitstatus[j]="ON";
            else
                Unitstatus[j]="OFF";
            Unitcredit[j]+=1;       
            cout<<"Unit "<<j<<" is "<<Unitstatus[j]<<" with credits: "<<Unitcredit[j]<<endl;
        }
        for(int j=num;j<p;j++)
        {
             cout<<"Unit "<<j<<" is "<<Unitstatus[j]<<" with credits: "<<Unitcredit[j]<<endl;
        }
      
   }
   return 0;
}

This code is in c++ and totally working

Here is java code:

/*package whatever //do not write package name here */

import java.io.*;
import java.util.Scanner;
import java.util.Random;

class GFG {
   public static void main (String[] args) {
       int p,t;
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter the number of units:");
       p = sc.nextInt();
       System.out.println(p);
       System.out.println("Enter the number of hours:");
       t = sc.nextInt();
       System.out.println(t);
       String[] Unitstatus= new String[p];
       int[] Unitcredit= new int[p];
       for(int i=0;i<p;i++)
       {
            Unitstatus[i]="ON";
            Unitcredit[i]=0;
       }
       //for every demand hour
     
   for(int i=1;i<=t;i++)
   {
        //generate random number between 0 and p
        Random rand = new Random();
        int num = rand.nextInt(p+1);
        System.out.println("In hour "+i+" we need to shut down "+num+" units:");
        for(int j=0;j<num;j++)
        {   if(Unitstatus[j]=="OFF")
                Unitstatus[j]="ON";
            else
                Unitstatus[j]="OFF";
            Unitcredit[j]+=1;     
            System.out.println("Unit "+j+" is "+Unitstatus[j]+" with credits: "+Unitcredit[j]);
        }
        for(int j=num;j<p;j++)
        {
             System.out.println("Unit "+j+" is "+Unitstatus[j]+" with credits: "+Unitcredit[j]);
        }
    
   }
      
   }
}

.

Similar Solved Questions

1 answer
We were unable to transcribe this imageShowyourwork 8. Bond Pricing. A 6-year Circular File bond with...
We were unable to transcribe this imageShowyourwork 8. Bond Pricing. A 6-year Circular File bond with face value $1,000 pays interest once a year of $80 and sells for $950. (L06-2) a. What is its coupon rate? b. What is its yield to maturity? c. If Circular wants to issue a new 6-year bond at face v...
1 answer
Negros Island Navigation has the following information for bank reconciliation Bank Balance as of December 1,...
Negros Island Navigation has the following information for bank reconciliation Bank Balance as of December 1, 2020 -50,000.00 Deposits--- --90,000.00 Checks issued --45,000.00 Bank Service Charge --500.00 Note Collected, including interest of P300.00,0------5,600.00 A check amounting to 1,000.00 was...
1 answer
Matlab! Use Matlab to calculate array X and array Y. The first column is time (1,...
Matlab! Use Matlab to calculate array X and array Y. The first column is time (1, 2, 3 ...), and the second column is value (0 and 1). When the value of array X is 0, the value of array Y is itself at the same time. When the value of array X is 1, the value of array Y will become the value of the pr...
1 answer
Question 4 View Policies Current Attempt in Progress Culver Company acquires a delivery truck at a...
Question 4 View Policies Current Attempt in Progress Culver Company acquires a delivery truck at a cost of $76,000. The truck is expected to have a salvage value of $6,000 at the end of its 4-year useful life. Assuming the declining-balance depreciation rate is double the straight-line rate, compute...
1 answer
Which Group 16 element combines with hydrogen to form compound that has the strongest hydrogen bonding between its molecules?
Which Group 16 element combines with hydrogen to form compound that has the strongest hydrogen bonding between its molecules?...
1 answer
7. A researcher wants to know whether the acidity of rain (pH) near Houston, Texas, is...
7. A researcher wants to know whether the acidity of rain (pH) near Houston, Texas, is significantly different from that near SC Chicago, Illinois. He randomly selects 12 rain dates in Texas and 14 rain dates in Illinois and obtains the following data: Texas 4.69 5.10 5.22 4.46 4.93 4.65 5.22 4.76 4...
1 answer
Save & Exit Submit Help Saved O Homework eck my work mode : This shows what...
Save & Exit Submit Help Saved O Homework eck my work mode : This shows what is correct or incorrect for the work you have completed so far. It does not indicate completion. Return to question Finishing Touches has two classes of stock authorized: 8 %, $10 par preferred, and $1 par value common. ...
1 answer
Suppose that the labor market for high school chemistry teachers is initially in equilibrium. Chemistry teachers...
Suppose that the labor market for high school chemistry teachers is initially in equilibrium. Chemistry teachers use laboratory chemicals as an important part of their jobs. New environmental regulations ban the use of many chemicals, which means that fewer laboratory chemicals are available for hig...
1 answer
Please I need help with F AND G Extra Credit: The Titration of Na2CO3 with HCl...
Please I need help with F AND G Extra Credit: The Titration of Na2CO3 with HCl (25 pts) (You must show work to earn credit!) 1. A 0.1983 g sample of Na2CO3 was dissolved in 100.00 mL H20. That solution was titrated with 0.1531 M HCl as titrant. The pKai and pKaz of carbonic acid (the conjugate acid...
1 answer
You have a 5.0 ml sample of a protein in 0.5M NaCI. You place the protein/salt...
You have a 5.0 ml sample of a protein in 0.5M NaCI. You place the protein/salt sample inside dialysis tubing and place the bag in a large beaker of distilled water. Your goal is to remove as much NaCI from the sample as possible. Since you know that the final salt concentration will be the same insi...
1 answer
Cakery Bakery received $1,000 from a customer on August 5, 2016 for a wedding cake to...
Cakery Bakery received $1,000 from a customer on August 5, 2016 for a wedding cake to be delivered on September 19, 2016. What would Cakery Bakery record on their books when the cake is successfully delivered?...
1 answer
Zurich Company reports pretax financial income of $70,000 for 2017. The following item causes taxable income to be different than pretax financial income: Q10 10PTS Rent revenue on the tax return...
Zurich Company reports pretax financial income of $70,000 for 2017. The following item causes taxable income to be different than pretax financial income: Q10 10PTS Rent revenue on the tax return is greater than rent revenue recognized on the income statement by $22,000. Zurich's tax rate is 30%...
3 answers
What’s Sin A cos A and tan A for a triangle with the opposite of 15 and a hypotenuse of 39?
What’s Sin A cos A and tan A for a triangle with the opposite of 15 and a hypotenuse of 39?...
1 answer
Four point charges are fixed at the corners of a square centered at the orign. The...
Four point charges are fixed at the corners of a square centered at the orign. The length of each side of the square is 2a. The charges as located as follows: +q is at a, +a) +5g is at ta +a) 2q is at ta a and +5q Is at (-a, -a). A fifth particle that has a mass m and a charge s placed at the origln...
1 answer
The following selected transactions relate to investment activities of Ornamental Insulation Corporation during 2018. The company...
The following selected transactions relate to investment activities of Ornamental Insulation Corporation during 2018. The company buys debt securities, intending to profit from short-term differences in price and maintaining them in an active trading portfolio. Ornamental’s fiscal year ends on...
1 answer
Which property of small nanoparticles makes them especially useful for catalysis? a. b. c. d. high...
Which property of small nanoparticles makes them especially useful for catalysis? a. b. c. d. high surface-area to volume ratios altered electronic structures for small sizes reactive surface sites All of the above....