C/C++ :: Application To Calculate Area And Perimeter Of Geometric Shapes

Oct 18, 2013

How would this look like in C? Develop an application to calculate the area and perimeter of geometric shapes. First the user is asked to enter a letter representing the shape. We use C for circle, R for rectangle and S for square. After the user chooses the shape, the program prompts for the appropriate dimensions of the shape accordingly.

For instance, if the user has chosen a square, the program will ask for a side. If it's a circle, the program will ask for radius. If it's a rectangle, it will ask for length and width. Upon receiving the appropriate dimensions, the program will calculate the area and the perimeter of the requested shape and print it on the screen. And again, the code will ask for another letter. If the user enters 'Q' the program terminates.

Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >S
Please enter the side of the square > 8
The area is 64 and the perimeter is 32
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >R
Please enter the width of the rectangle > 5
Please enter the length of the rectangle > 7
The area is 35 and the perimeter is 24
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >Q

View 1 Replies


ADVERTISEMENT

C++ :: Calculate Area And Perimeter Of A Rectangle

Jan 28, 2013

Write a program that prompts the user to input the length of a rectangle and the width of a rectangle and then displays the rectangle's area and perimeter. The program should be broken down in 3 parts:

1. Input the length and the width (two input statements)

2. Calculate the area & perimeter (results should be saved in variables

3. print results.

Format the output so the user can easily read the results. Use the tab escape so its easy to read.
---------------------------------------------------------------
So here's what I have so far. I have been stuck for two days

#include iostream
using namespace std;
int main () {
int double length;
int width;
int area;
int perimeter;

[Code] ....

I dont want to get a zero for not turning this in...

View 14 Replies View Related

C++ :: Calculate Surface Area Of Various Shapes - Symbolic Constant For The Value Of PI

Mar 2, 2013

This error keeps coming.

******************************************************************
CSCI 240 Program 5 Part 2 Spring 2013

Programmer:
Section: 1
Date Due: 3/1/13

Purpose: This program uses functions to calculate the surface area of various shapes. It is an exercise in learning to write functions.
******************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.14
//Symbolic constant for the value of PI

int Menu();
int getValue( string prompt, int lowerBound, int upperBound );

[Code] .....

View 10 Replies View Related

C++ :: Calculating Area And Perimeter

Sep 28, 2014

I am having trouble with my C++ program. My program asks the user to enter any number greater than 0 and less than 20, and if the user enters any number(s) outside the acceptable range, the output should display:

input outside of exceptable range > 0 and < 20
length: 1 width: 1 area: 1 perimeter: 1

But in my program, this output displays no matter what the user types (even if the numbers are in the acceptable range, when it should be displaying the length and width the user enters and also displaying the calculated perimeter and area whenever the user enters number(s) in the acceptable range. Here is my code:

#include <iostream>
using namespace std;

float class_rectangle_area();
float class_rectangle_perimeter();
float class_rectangle_length();
float class_rectangle_width();

[Code] .....

View 4 Replies View Related

C++ :: Finding Area And Perimeter Of Given Coordinates

Dec 10, 2014

Below is what i have so far. My main issue is outputting the area and perimeter of the given coordinates as i need the final coordinate to connect up to the first coordinate. I've tried doing that using numberOfcorners but it says "the expression must have integral or enum type"

#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;
int main() {

float ArrayX[10];
float ArrayY[10];
float numberOfcorners;

[Code] .....

View 3 Replies View Related

C++ :: Calculate Area Of Circle Without Pi

Mar 22, 2013

I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.

Code:
#include<iostream>
#include<cmath>
using namespace std;
int main ()

[Code] .....

View 7 Replies View Related

C++ :: Calculate Area And Volume Of Cylinder?

Apr 27, 2013

I would like to calculate area and volume of cylinder but radious and height should be integer, float and double. How can i do?

View 9 Replies View Related

C++ :: Calculate Area Using Rectangle / Trapezoid Or Both

Feb 17, 2014

#include <iostream>
#include <cmath>
using namespace std;

//prototypes for all separate functions
int chooseFunc(int);
int chooseMethod(int);
int numRect(int);

[Code] .....

It seems that my program will ask the user for the number of rectangles and trapezoids but will fail to compute the area under the curve from the user input. Therefore, I believe I have a logical error somewhere or I'm forgetting to call something somewhere.

View 1 Replies View Related

C :: Calculate Area Of Rectangle - Variable R Is Being Used Without Being Initialized

Mar 15, 2014

I am writing a program to calculate a rectangle's area.

Eg.
Enter top left point: 1 1 (User input)
Enter bottom right point: 2 -1 (User input)
Top Left x = 1.000000 y: 1.000000
Bottom Right x = 2.000000 y: -1.000000
Area = 2.000000 (Program output)

It keeps on prompting me my variable r is being used without being initialized, when I think I already did so.

Code:
typedef struct {
double x;
double y;
} Point;

[Code] ....

View 8 Replies View Related

C :: How To Calculate Surface Area And Volume For Rectangular Prism

Jan 24, 2015

So for my assignment, I have to write code to calculate the surface area and volume for a rectangular prism that involves the use of functions. I made the program without functions and it works perfectly but as I'm putting in the required functions, it conversely made it non-functional, ironically. How to call functions correctly and the online book we're using now is confusing me even more.

Code:

#include <stdio.h>
#include <math.h>
int main(void) {
double x1, x2, x3, x4, x5, x6, x7, x8 = 0;
double y1, y2, y3, y4, y5, y6, y7, y8 = 0;
double z1, z2, z3, z4, z5, z6, z7, z8 = 0;
double length, width, height=0;

[Code]....

And here is the version I'm using to test it (without the need to input the individual coordinates).

Code:

#include <stdio.h>
#include <math.h>
int main(void) {
double x1, x2, x3, x4, x5, x6, x7, x8 = 0;
double y1, y2, y3, y4, y5, y6, y7, y8 = 0;
double z1, z2, z3, z4, z5, z6, z7, z8 = 0;
double volumePrism, surfaceArea =0;

[Code]...

View 3 Replies View Related

C++ :: Calculate Area For 500 Different Measurements For Playground Company In Region

Feb 13, 2014

You are writing a program to calculate the area for 500 different measurements for a playground company in the region. The company must calculate square footage of each prospective playground, as well as the total cost to mulch each area. The cost of mulch changes frequently, so the company would like to be able to input the current cost per square foot of mulch each time they run the program. Since the quantity of data is large, the input should come from a file called “measurements.txt”. You can assume the file includes the length of each prospective playground, followed by the width. The file will be in the following format.

450300
120210
.
.
.

Ask the user the name of the file they would like to write to, as well as the current price of mulch per square foot. Output the area of each playground, along with the total price of mulch to the file that the user specifies. The playground company would like each column of output to be 20 characters in width. Each column should have an appropriate heading in the output file. You should format your output data appropriately. For example, for the input data displayed above, along with a $2.00 per square foot mulch price, the output would be:

Area Total Mulch Price
135000 $270000.00
25200 $50400.00

View 3 Replies View Related

C++ :: Structured Data - Nesting Triangles Using Structs And Doing Some Geometric Calculation

Sep 8, 2013

nestedTriangles.cpp description:

The program takes as input a pair of triangles, specified be giving the coordinates of each trangle's vertices. It then determines if either triangle is "nested" within the other, meaning that one triangle lies entirely within the interior of the other.

Pseudocode:

One triangle lies within another if and only if all three vertices of the first triangle lie within the interior of the second triangle.

Suppose that we have a triangle with vertices A, B, and C, described by the coordinates (xA, yA), (xB, yB), and (xC, yC), respectively. The sides of the triangle are the line segments AB, BC, and CA.

A line passing through two points (x1, y1) and (x2, y2) can be considered to be the set of points (x,y) satisfying the equation

f(x,y) = 0
where f(x,y) is given as
f(x,y) = (x - x1) (y2 - y1) - (y - y1) (x2 - x1)

One of the interesting things about that f(x,y) is that we can use it to determine which "side" of the line an abitrary point (x,y) is on:

If f(x,y) = 0, the point is exactly on the line. All points for which f(x,y) > 0 are on one side of the line, and All points for which f(x,y) < 0 are on the other side So the problem of determining whether a point (x,y) is on the inside of a trangle can be checking the sign of f(x,y) for each of the three lines making up the triangle. A complicating factor is that we don't know, for any given triangle, whether those three signs should be all positive, all negative, or some mixture of the two.

The centroid of a triangle can be computed as the "average" of the x and y coordinates of the vertices:

xcen = (xA + xB + xC)/3
ycen = (yA + yB + yC)/3

This point (xcen, ycen) is definitely inside the trangle (unless the triangle is "degenerate" and has no interior points). The problem of determining whether (x,y) is on the inside of a triangle can therefore be resolved by checking to see if it is on the same side of each of the trangle's line segments as (xcen, ycen).

What I need:

I want to fill in the missing bodies for the functions eval and areOnSameSideOf, which manipulate line segments. I think calling eval from within areOnSameSideOf will simplify the implementation of the latter.

Code:
#include <iostream>
using namespace std;
/**
* 2D Cartesian coordinates
*/

[Code]....

View 2 Replies View Related

C++ :: Structured Data / Nesting Triangles Using Structs And Doing Some Geometric Calculation?

Sep 8, 2013

nestedTriangles.cpp description:

The program takes as input a pair of triangles, specified be giving the coordinates of each trangle's vertices. It then determines if either triangle is "nested" within the other, meaning that one triangle lies entirely within the interior of the other.

Pseudocode:

One triangle lies within another if and only if all three vertices of the first triangle lie within the interior of the second triangle.Suppose that we have a triangle with vertices A, B, and C, described by the coordinates (xA, yA), (xB, yB), and (xC, yC), respectively. The sides of the triangle are the line segments AB, BC, and CA.A line passing through two points (x1, y1) and (x2, y2) can be considered to be the set of points (x,y) satisfying the equation

f(x,y) = 0
where f(x,y) is given as
f(x,y) = (x - x1) (y2 - y1) - (y - y1) (x2 - x1)

One of the interesting things about that f(x,y) is that we can use it to determine which "side" of the line an abitrary point (x,y) is on:

If f(x,y) = 0, the point is exactly on the line.

All points for which f(x,y) > 0 are on one side of the line, and All points for which f(x,y) < 0 are on the other side So the problem of determining whether a point (x,y) is on the inside of a trangle can be checking the sign of f(x,y) for each of the three lines making up the triangle.

A complicating factor is that we don't know, for any given triangle, whether those three signs should be all positive, all negative, or some mixture of the two.

The centroid of a triangle can be computed as the "average" of the x and y coordinates of the vertices:

xcen = (xA + xB + xC)/3
ycen = (yA + yB + yC)/3

This point (xcen, ycen) is definitely inside the trangle (unless the triangle is "degenerate" and has no interior points).

The problem of determining whether (x,y) is on the inside of a triangle can therefore be resolved by checking to see if it is on the same side of each of the trangle's line segments as (xcen, ycen).

I want to fill in the missing bodies for the functions eval and areOnSameSideOf, which manipulate line segments. I think calling eval from within areOnSameSideOf will simplify the implementation of the latter.

Code:
#include <iostream>
using namespace std;
/**
* 2D Cartesian coordinates
*/
struct Point {
double x;
double y;

[code]...

View 1 Replies View Related

C++ :: How To Compute Perimeter Of A Triangle

Jun 26, 2013

I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.

#include <iostream>
#include <cmath>
using namespace std;

struct Point{
double x;
double y;

[Code] ......

I expect to get 0 for triangle1, but I get some strange value...

Here is the result

Type x for point1 : 1
Type y for point1 : 1
Type x for point2 : 3
Type y for point2 : 1
Type x for point3 : 1
Type y for point3 : 3
The perimeter of the triangle1 is : 2.82843
The perimeter of the triangle2 is : 6.82843

View 2 Replies View Related

C :: Making HTML Shapes

Oct 13, 2014

So basically I have to write a C program that, when opening the html file in a browser, looks essentially like this: (Size, position, color of the shapes doesn't matter so long as I have one of each shape and the box surrounding them. Words up top dont matter either.)

This is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#define FILENAME ("A4P1.html")
[code]....

Anyways i can get the individual shapes, but I don't know how to get all the shapes to appear at once..

View 6 Replies View Related

C++ :: How To Use Mouse In Drawing Shapes

May 3, 2013

i have to make an application called " paint " in c++ . It should facilitate user to draw different shapes using a mouse. Now the biggest hurdle i am facing is the usage of mouse .. what is the header file for usage of mouse ? i am using visual studio 2010 . the syntax is creating problems ..

View 1 Replies View Related

C/C++ :: How To Draw Shapes Using Loop

Apr 11, 2014

How can I draw thus shape using loop for
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5

Also this shape
1*****
12****
123***
1234**
12345*
123456

View 6 Replies View Related

C :: Different HTML Shapes With Random Attributes

Oct 21, 2014

This time I need to generate random shapes (circles, rectangles, squares, and ellipses) with random attributes with C, to html.

I am able to create specific shapes with random attributes, but I am unsure how to have the function create a random shape...

Also, the function "box" is meant to create a black border around the shapes. It does this, but I do not know how to make it so that the other shapes do not show up along the lines of this "box."

I guess it appears that certain shapes are "layered" over top of others? ie. My circles/ellipses always show up on top of the rects/squares/box.Currently I have this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define NO_SHAPES 10
#define X_RANGE 797
#define Y_RANGE 397

[Code] .....

View 4 Replies View Related

C++ :: GetImage Function - Save Other Shapes Except Rectangle?

Jan 11, 2012

GetImage func give up this parameters :

getimage(int left,int top,int right,int bottom,void far *bitmap);

so Getimage save a rectangle shape on *bitmap.

Is it possible that we can save the other shapes except rectangle? circle,or star, or...

View 5 Replies View Related

Visual C++ :: Fill Color In Shapes Using FLTK Doesn't Work For Circles

Aug 28, 2014

I installed FLTK 1.3.X from [URL] on my visual studio 2012 compiler and use PPP book for C++ programming [URL]. My problem is about filling a Shape in.

Code:
#include <Simple_window.h>
using namespace Graph_lib;
int main() {
Simple_window win(Point(100,100), 1000, 600, "Binary_tree");
Graph_lib::Circle c(Point(200,200),50);
c.set_color(Color::red);

[code]....

When I run the program, All three Shapes are drawn on window but only the Rectangle is filled in! Why? set_color works for the three and apparently the set_fill_color is defined for all Shapes and it too should work but why it doesn't for Circle and Ellipse?

This [URL] is the .CPP and .h files ( )

View 6 Replies View Related

C# :: Server Application Using Tcp Protocol And Then Establish Connection With A Client Application

Nov 29, 2014

What happens if I make a server application using tcp protocol and then establish connection with a client application but the server crash and then the client send data. Will the data be lost or the system will continue trying to send it?

View 2 Replies View Related

C# :: How To Start Application And Automatically Pass Input To That Application

May 9, 2012

I want to create an application that starts an application and passes input to that application. I know how to start a process using the classes in System.Diagnostics, but I don't know how to pass data to the process.

For example, and this is just an example, I would like to be able to automatically start an application that requires a username and password and automatically enter the username and password. Of course, that might open the door to security vulnerabilities, but that's not the point of the exercise.

How to implement the functionality I described? Is there a general way to go about doing this or does it depend entirely on the idiosyncrasies of the application in question?

View 2 Replies View Related

C Sharp :: Run Application When Log Off In Console Application

Oct 4, 2012

i have task scheduling application which execute every 30 minute i want to keep this process when system is log off in c# console application

View 2 Replies View Related

C/C++ :: Area Of Triangle Calculator?

Nov 16, 2014

I was asked to build a small program to calculate the are of a Triangle but my code must have some problem.. />

#include "stdafx.h"
void main()
{
int a,b;

[Code]....

I get this errors:

-warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

-warning C4244: '=' : conversion from 'int' to 'float', possible loss of data

View 4 Replies View Related

C/C++ :: Program That Uses The Radius To Get Area?

Apr 28, 2012

How can i come up with a program that uses entered radius of a circle to find its area

View 1 Replies View Related

C++ :: Area And Volume Of Cylinder?

Apr 27, 2013

I would like to calculate area and volume of cylinder but radious and height should be integer, float and double.

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved