Question

In: Computer Science

Write a program that calculates the average of upto 100 English distances input by the user....

  1. Write a program that calculates the average of upto 100 English distances input by the user. Create an array of objects of the Distance class, as in the ENGLARAY example in this chapter. To calculate the average, you can borrow the add_dist() member function from the ENGLCON example in Chapter 6. You’ll also need a member function that divides a Distance value by an integer. Here’s one possibility:

        void Distance::div_dist(Distance d2, int divisor)
           {
    

    float fltfeet = d2.feet + d2.inches/12.0; fltfeet /= divisor;
    feet = int(fltfeet);
    inches = (fltfeet-feet) * 12.0;

    }

Solutions

Expert Solution

the code is

 #include<iostream>
#include<string>
#include<iomanip>
#include<conio.h>
using namespace std;

class Distance1{
      int feet; float inches;
   public:
   Distance1(): feet(0), inches(0) {}
      void getdist(){
      cout<<"\nEnter feet: "; cin>>feet;
      cout<<"Enter inches: "; cin>>inches;}
   void add_dist(Distance1 d2, Distance1 d3);
   void div_dist(Distance1 d2, int divisor);
      void showdist() const { cout<<feet<<"\'-"<<inches<<'\"';}};

void Distance1::add_dist(Distance1 d2, Distance1 d3)
{
   inches=d2.inches+d3.inches; feet=0;
   if(inches>=12.0){ inches -= 12.0; feet++;}
   feet += d2.feet+d3.feet;
}

void Distance1::div_dist(Distance1 d2, int divisor)
{
   float fltfeet=d2.feet+d2.inches/12.0;
   fltfeet /= divisor; feet=int(fltfeet);
   inches=(fltfeet-feet)*12.0;
}

int main(void)
{
 
 cout<<"-------------------------------------------------------------------------------\n"<<endl;
 
 Distance1 dist[100], tmp; int i=0;
 

 dist[i].getdist(); tmp.add_dist(tmp, dist[i++]);
 

 tmp.div_dist(tmp, i); cout<<"\nAverage is: "; tmp.showdist();

}


 

I am also attaching the output please find the output

hope this is helpful

please please please upvote if it is helpful


Related Solutions

Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Write a program to take input of scores for Chemistry, Biology and English for a student...
Write a program to take input of scores for Chemistry, Biology and English for a student and display the average with 2 decimal places if all of the three scores are in the range between 1 and 100 inclusive. Program should also display the course name for which scores are entered out of range telling Average couldn't be calculated. Following is a sample run: Enter scores for Chemistry, Biology and English between 1 and 100: 45 89 96 Avg score...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Write a program that encrypts and decrypts the user input. Note – Your input should be...
Write a program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x) given by...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
jgrasp environment, java write a complete program that calculates a restaurant bill. Prompt the user for...
jgrasp environment, java write a complete program that calculates a restaurant bill. Prompt the user for the check amount, then ask the user what type of tipp they would like to leave: the choices are 1 for good tip (20%), 2 for an average tip (15%), or 3 for poor tip (10%). Use their input and an if-else to calculate the tip amount. Then calculate and output the final bill: check+tip print out the bill, exactly as shown (print the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT