Question

Problem: Create a program that will ask scientist in tracking the resistances of products from various...

Problem: Create a program that will ask scientist in tracking the resistances of products from various
batches. The resistances of good resistors should be between 3 and 3.5 inclusive. Your program will
need to track the number of resistances that are too high (>3.5 ohms), the number of resistances that
are too low (<3.0ohms) and calculate the average of the resistances that fall in the proper range (>=3
and <= 3.5).
Your program should prompt the user to enter name of the batch (the batch name may contain spaces)
and the number of resistors in that batch. Then use a while loop to check that the entered number of
resistors is at least one and prompt the user to re-enter the number of resistors in the batch when it is
not. (This while loop should not contain any selection structures.) Next use a for loop to enter the
resistance for each resistor in the batch The for loop should determine the number of resistors that
had a valid resistance that was too low (< 3), the number of resistors that had a resistance that was too
high (>3.5) and the average resistance from those resistors that passed (the resistance of >= 3 and <=
3.5) . Another while loop should be used to prompt the user to re-enter an invalid resistance of 0 or
less. (Again this while loop should not contain any selection structures.) Resistances of 0 or less
should not be counted as being entered. Only valid values (>0) should be included with the count of
entered resistances. After the for loop output the batch name, the number of resistors that were in the
batch, the numbers of resistances that were too low, the number of resistances that were too high and
the average resistance of the resistors that passed. Use a do-while loop to evaluate another batch if the
user indicates the he/she has another batch by entering a y (if there is another batch) or n (if there is not
another batch). Between iterations of the do-while loop the number of resistors in the batch, the
number of resistors that were too high, the number of resistors that were too low, and the average
should be set to 0. Sample output is given below.
Your code should not use any concepts beyond Chapter 5 of your textbook (e.g. arrays or programmer-
built functions) or use any Boolean variables. Your code should employ a single string object to store
the batch name and use descriptive (no single characters) for variable names. Remember to write
appropriate conditions for all your loops. The while loops to check input should not contain any
selection structures, instead the condition of the loop should check the input. Design your code
minimize the number of relational expressions used.

in C++ please
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ program to calculate resistance with comments

#include<bits/stdc++.h>

using namespace std;

int main()

{

    //character to see whether user want to enter another batch or not

    char ch;

    do

    {

        cout<<"Enter batch name\n";

        string batch_name;

        cin>>batch_name;

        cout<<"Enter the number of resistors in the current batch\n";

        // high resistors is the count of total number of resistors that were too high

        // same for low resistors

        int total_resistors=0,high_resistors=0,low_resistors=0;

        double avg_resistance=0,sum_avg_resistors=0;

        cin>>total_resistors;

        // if total resistors is 0 or less then enter again

        while(total_resistors<1)

        {

            cout<<"Please enter number of resistors(atleast one)\n";

            cin>>total_resistors;

        }

        // for loop for entering resistance of all resistors of this batch

        for(int i=0;i<total_resistors;i++)

        {

            double curr_resistance;

            cout<<"Enter resistance for resistor "<<(i+1)<<endl;

            cin>>curr_resistance;

            // if resistance entered is negative or zero then enter again

            while(curr_resistance<=0)

            {

                cout<<"Again enter correct resistance for resistor "<<(i+1)<<endl;

                cin>>curr_resistance;

            }

            // if resistance is greater than 3.5 then increment count of total number of high resistors

            if(curr_resistance>3.5)

            high_resistors++;

            // else if resistance is less than 3.0 then increment count of total number of low resistors

            else if(curr_resistance<3.0)

            low_resistors++;

            // else increment sum of resistance of avg resistors

            else

            sum_avg_resistors+=curr_resistance;

        }

        // find total number of average resistors

        int avg_resistors=total_resistors-high_resistors-low_resistors;

        // calculate average resistance

        avg_resistance=sum_avg_resistors/avg_resistors;

        // print the information

        cout<<"Batch name is "<<batch_name<<endl;

        cout<<"Number of resitors in the batch are "<<total_resistors<<endl;

        cout<<"Number of too high resitors in the batch are "<<high_resistors<<endl;

        cout<<"Number of too low resitors in the batch are "<<low_resistors<<endl;

        cout<<"Average resistance of this batch is "<<avg_resistance<<endl;

        

        // prompt user for another batch

        cout<<"Do you want to evaluate another batch(y for yes, n for no)?"<<endl;

        cin>>ch;

        // if ch=='y' then proceed again

    }while(ch=='y');

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
Problem: Create a program that will ask scientist in tracking the resistances of products from various...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In c# create a program that generates a random number from 1 to 1000. Then, ask...

    In c# create a program that generates a random number from 1 to 1000. Then, ask the user to guess the random number. If the user's guess is too high, then the program should print "Too High, Try again". If the user's guess is too low, then the program should print "Too low, Try again". Use a loop to allow the user to keep entering guesses until they guess the random number correctly. Once they figure it, congratulate the user....

  • Guess the number! You will create a program that will ask the user to guess a...

    Guess the number! You will create a program that will ask the user to guess a number between 1 and 10. The pseudocode is below. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number week 4 #Name: #Date: #Random number, loop while true #ask user for number. #if number is too high or too low, tell user, if they guessed it break out of loop...

  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • in Java, temperature problem Create a package named temperature and create a program that has a...

    in Java, temperature problem Create a package named temperature and create a program that has a while loop. • • Inside the while loop, your program will prompt the user for temperature in Centigrade. If the Centigrade value read in is <= -100. the loop will exit. Otherwise, your program will compute the Fahrenheit equivalent temperature. Inside the while loop, your program will print out the Centigrade and Fahrenheit temperatures. Keep a count of the valid user inputs and a...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should...

    Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should output 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.ser to input a number, and then using a loop control statement (While, For, Do-While), output to the console the numbers beginning from 1, up to and including the number input by the user.

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • Write a code for a ride tracking app for Large Resort parks. In your app users...

    Write a code for a ride tracking app for Large Resort parks. In your app users are going to be able to track wait times for up to five attractions, find the shortest wait time, and find the average wait time. //-----------------------------Sample Program Behavior with five attractions entered--------------------- Welcome to Large Resort Parks! Please enter the attractions you plan to visit and their wait times Ride 1 info: Attraction Name: 80 ft drop Wait time (in minutes): 40 Enter another...

  • (c++) Write a program that generates a random number between 1 and 100 and asks the...

    (c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT