Question

In: Computer Science

Write a C++ program that takes input from the keyboard of the 3 dimensions of a...

Write a C++ program that takes input from the keyboard of the 3 dimensions of a room (W,L,H in feet) and calculates the area (square footage) needed to paint the walls only. Use function overloading in your program to pass variables of type int and double. You should have two functions: one that accepts int datatypes and one that accepts double datatypes. Also assume a default value of 8 if the height parameter is omitted when calling the functions.

Solutions

Expert Solution

Function overloading is the technique of calling same function name with different parameter

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

a room has 1 floor, 4 walls, 1 roof. suppose we have to paint 4 walls and 1 roof. then

total area = 4 walls area+ 1roof area

                = 2 opposit walls( length * height) + 2 opposit walls (breadth* height)

                 + 1 roof( length * breadth)

                =2*(L*H)+2*(B*H)+L*B;

user will input height but we will omitt it and use default value 8.

#include<iostream>
using namespace std;

int function(int x,int y,int z) // SAME FUNCTION NAME
{
        int L=x;
        int B=y;
        int H=z;
        int area=2*(L*H)+2*(B*H)+L*B;
        cout<<"\n passing int data type \n ";
        return area;
}

double function(double x,double y,double z) // SAME FUNCTION NAME
{
        double L=x;
        double B=y;
        double H=z;
        double area=2*(L*H) + 2* (B*H) + L*B;
        cout<<"\n passing double data type \n ";
        
        return area;
}

int main()

{
        cout<<"\nwhich function do you want to use :\n 1.type double \n 2.type int \nenter (1/2) :";
        int option;
        cin>>option;
        
        if (option==1)
        {
        
        float L,B,H;
        
        cout<<"\nenter the length: ";
        cin>>L;
        cout<<"enter the Bredth: ";
        cin>>B;
        H=10;
        cout<<"enter the height: ";
        cin>>H;
        cout<<"\n total area in square foot= "<<function(L,B,8.0)<<"\n\n"; // calling function , height omitted, default value of 8 used
    }
    else if(option==2)
    {
        int L,B,H;
        
        cout<<"\nenter the length: ";
        cin>>L;
        cout<<"enter the Bredth: ";
        cin>>B;
        cout<<"enter the height: ";
        cin>>H;
        cout<<"\n total area in square foot= "<<function(L,B,8)<<"\n\n"; // calling function , height omitted, default value of 8 used
   }
        else
        {
                cout<<"invalid option\n";
        }
        
        return 0();
}
 

output


Related Solutions

Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
Write a program that prompts the user to input their first name from the keyboard and...
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE ! You...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The...
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n...
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n = 50) and displays the string representations of those numbers with following conditions If the current number is divisible by 2, then print CSU If the current number is divisible by 5, then print SB If the current number is divisible by both 2 and 5, then print CSUSB If the number is neither divisible by 2 nor 5, then print the number Example:...
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
In C write a program that asks the user for the dimensions of 3 sides of...
In C write a program that asks the user for the dimensions of 3 sides of a triangle. Each side dimension must be between 1.00 and 100.00 including 1.00 and 100.00. If the side dimensions indeed can make a valid triangle then the program should use these values to determine the perimeter and the area of the valid triangle 1. Must use programmer define functions 2. Your program must have at least 4 functions, main and the following 3 functions:...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
Write a program which takes 3 inputs values as dimensions of a cuboid. Do the following-...
Write a program which takes 3 inputs values as dimensions of a cuboid. Do the following- 1. Verify it forms a cuboid (non zero, non negative and non-integer inputs). 2. Show the longest and shortest edges. 3. Calculate the surface area of the square made by the two short edges. 4. Calculate the volume of the cuboid. Refer the following to learn about the cuboid (generally this is called the domain knowledge) https://www.math-only-math.com/cuboid.html Volume and Surface Area of Cuboids and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT