Question

In: Computer Science

Write a C++ program using separate void which asks the user to input side of a...

Write a C++ program using separate void which asks the user to input side of a square, radius of a circle , height and base of a triangle and finds the area of squares, circles and triangles. Then using main function display the area of square, circle and triangle

Solutions

Expert Solution

#include<iostream>
using namespace std;
//reads the input into variables using references
void readInput(double &side,double &radius,double &height ,double &base){
        cout<<"Enter side of sqaure: ";
        cin>>side;
        cout<<"Enter radius of circle: ";
        cin>>radius;
        cout<<"Enter base and height of triangle: ";
        cin>>base>>height;
}
int main(){
        double side,radius,height,base;
        readInput(side,radius,height,base);
        // formula : a^2
        cout<<"Square area: "<<side * side<<endl;
        // formula 2 PI R
        cout<<"Circle area: "<<2 * 3.1415 * radius<<endl;
        // formula BH/2
        cout<<"Triangle area: "<<base * height/2<<endl;
        
}


Related Solutions

Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference between the largest and the smallest. You should ask the user the number of integers s/he would like to enter (this will allow you to set the length of the array). Allow the user to input all the numbers and then store them in the array. Search the array for the largest number, then search for the smallest, and finally compute the calculation. Display...
In C++ Write a program which asks the user his/ her major, stores it in a...
In C++ Write a program which asks the user his/ her major, stores it in a variable called major, then asks What is your GPA? and stores it in a variable called gpa. Next, ask a question based on the answers from the previous two questions. For example: What is your major? computer science What is your gpa? 3.52 computer science is very hard; why do you think you have a gpa of 3.52?
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Write a program that asks the user to input a set of floating-point values. When the...
Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs.5 pts Your code with comments A screenshot of the execution Test Case:       Enter float: 1.0...
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.
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT