1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Fudgin [204]
2 years ago
7

You are required to write a calculator for Geometric shapes(Circle, Square, and Rectangle). The basic idea is that you willprovi

de the information regarding a geometric shape and yourprogram will calculate the area, circumference and perimeter.
Computers and Technology
1 answer:
denis23 [38]2 years ago
4 0

Answer: The c++ program to calculate area and perimeter for different geometric shapes is given below.

#include <iostream>

using namespace std;

void circle();

void square();

void rectangle();

int main() {  

string shape;

char choice;  

do

{

cout<<"Enter the geometrical shape (circle, square, rectangle)." <<endl;

cin>>shape;  

if(shape == "circle")

       circle();        

   if(shape == "square")

       square();        

   if(shape == "rectangle")

       rectangle();        

   cout<<"Do you wish to continue (y/n)"<<endl;

   cin>>choice;    

   if(choice == 'n')

       cout<<"quitting..."<<endl;        

}while(choice != 'n');

return 0;

}

void circle()

{

   float area, circumference;

   float r, pi=3.14;    

   cout<<"Enter the radius of the circle"<<endl;

   cin>>r;    

   circumference = 2*pi*r;

   area = pi*r*r;    

   cout<<"The circumference is "<<circumference<<" and the area of the circle is "<<area<<endl;    

}

void square()

{

   float area, perimeter;

   float s;    

   cout<<"Enter the side of the square"<<endl;

   cin>>s;    

   perimeter = 4*s;

   area = s*s;    

   cout<<"The perimeter is "<<perimeter<< " and the area of the square is "<<area<<endl;

}

void rectangle()

{

   float area, perimeter;

   float b, h;    

   cout<<"Enter the breadth of the rectangle"<<endl;

   cin>>b;    

   cout<<"Enter the height of the rectangle"<<endl;

   cin>>h;    

   perimeter = 2*(b+h);

   area = b*h;    

   cout<<"The perimeter is "<<perimeter<< " and the area of the rectangle is "<<area<<endl;

}

 

OUTPUT

Enter the geometrical shape (circle, square, rectangle).

circle

Enter the radius of the circle

3.56

The circumference is 22.3568 and the area of the circle is 39.7951

Do you wish to continue (y/n)

n

quitting...

Explanation:

The program performs for circle, square and rectangle.

A method is defined for every shape. Their respective method contains the logic for user input, computation and output.

Every method consists of the variables needed to store the dimensions entered by the user. All the variables are declared as float to ease the computation as the user can input decimal values also.

No parameters are taken in any of the methods since input is taken in the method itself.

You might be interested in
Programmers use _____ languages in the Rapid Application Development (RAD) methodology to facilitate code reuse?
photoshop1234 [79]
The Go programming language
8 0
3 years ago
simplify the expression below and state the value of m for which the simplified expression is not defined 2m² + m - 15/ m² - 9​
motikmotik

Answer:

  • The simplified expression is: \frac{2m-5}{m-3}
  • The simplified expression is undefined for m=3

Explanation:

The given expression is:

\frac{2m^2+m-15}{m^2-9}

The numerator can be siplified by using factorization and denominator will be simplified using the formula

a^2-b^2 = (a+b)(a-b)

So,

= \frac{2m^2+6m-5m-15}{(m)^2-(3)^2}\\=\frac{2m(m+3)-5(m+3)}{(m-3)(m+3)}\\=\frac{(2m-5)(m+3)}{(m-3)(m+3)}\\=\frac{2m-5}{m-3}

A fraction is undefined when the denominator is zero. In order to find the value of m on which the simplified fraction will be undefined we will put denominator equal to zero.

So,

m-3 = 0 => m = 3

Hence,

  • The simplified expression is: \frac{2m-5}{m-3}
  • The simplified expression is undefined for m=3
7 0
2 years ago
In your own words, describe the structure and function of both the stack and queue data structure and discuss how they are diffe
Kobotan [32]

Answer:

Following are the answer to this question:

Explanation:

Stack:

The stack data structure is used to create method, parsing, analysis of expression, and tracking. This data type uses the LIFO system, which stands from the Last In First Out. This data structure operates on the top side. In this data structure, it performs two methods, that are "push() and pop()" method and the time complexity of the stack data structure O(1).

Example of Stack:

import java.util.*;//import package

 public class Main //defining class Main

{      

public static void main (String[] ag)//defining main method  

  {

     ArrayDeque<Character> stack = new ArrayDeque<Character>();//creating Character array ArrayDeque  

       stack.push('A'); //add value in stack  

      stack.push('B');//add value in stack  

      stack.push('B'); //add value in stack  

      System.out.println("First Insert:"+stack); //print value         stack.pop();//remove value from stack    

    System.out.println("After removing element: "+stack); //print value         stack.push('B'); //add value in stack    

    stack.pop();//remove value from stack      

 System.out.println("final value: "+stack); //print value    

}

}

Output:

First Insert:[B, B, A]

After removing element: [B, A]

final value: [B, A]

Queue:

The queue data structure is an abstract type, it is similar to the stacks data structure. It is open at both ends when opposed to lines. It follows the FIFO method, which stands for the First-In-First-Out method, At one end data is inserted and at the other end, it deletes the data and the time complexity of the queue data structure O(1).

Example of Queue:

import java.util.*;//import package  

public class Main//defining a class queue

{  

    public static void main(String[] ars)//defining main method

    {  

      LinkedList<Integer> que= new LinkedList<Integer>();//defining integer array LinkedList    

      for (int i = 0; i < 5; i++)//defining fo loop to add value in queue  

     {    

        que.add(i); //use add method to insert value        

}        

System.out.println("Queue value: "+ que); //print queue value      

  int remove= que.remove(); //remove value from the queue          System.out.println("after removing value from queue: "+ remove);//removing element from queue  

      System.out.println(que);  //after removing the element print value  

  }

}  

Output:

Queue value: [0, 1, 2, 3, 4]

after removing value from queue: 0

[1, 2, 3, 4]

6 0
3 years ago
Is the computer a device that calculates and has the independence and initiative for the actions it performs?
inna [77]

Answer:

The answer is "True".

Explanation:

In this question, the given statement is true because the computer is a device that receives information as input, analyzes information utilizing a program that provides relevant information for the processed data, and in this, it performs numerous calculation and all the calculation will be store in its memory, which is used in the future for collect data on hard drives.

8 0
2 years ago
The enhanced for statement allows you to iterate through the elements of an array or a collection without using a counter. Give
lesya [120]

Answer:

Check the explanation

Explanation:

public class EnhancedForExample {

   public static void main(String[] args) {

       int[] arr = {4, 2, 9, 1, 5, 7};

       for(int num : arr) {

           System.out.println(num);

       }

   }

}

Kindly check the attached image below for the code output.

7 0
3 years ago
Read 2 more answers
Other questions:
  • This is a list of commands that tell your computer what to do. A icon B FAT C GUI D menu
    5·2 answers
  • Why was Unicode invented?
    6·1 answer
  • 1. Write a bash script to create 3 files of different size greater than 1700 kb and less than 1800 kb . The 2. Content of the fi
    9·1 answer
  • Joshua is creating his résumé, in which section will he add projects and trainings he was involved in?
    10·1 answer
  • 2.7 code practice question 1 edhesive
    13·2 answers
  • What is a unique text-based Internet address corresponding to a computer's unique numeric IP address called
    14·1 answer
  • A style ____ is a series of rules that defines the style for a web page or an entire web site.
    6·1 answer
  • List three different sets of keywords that could be used to search for information on how to
    15·1 answer
  • Where do charts get the data series names?
    14·1 answer
  • How did the use of ARPANET change computing?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!