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
ADVERTISEMENT
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
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
Mar 13, 2015
// create code so that 2 rectangular prisms are created and all appropriate information is displayed.
// In addition to displaying all appropriate information, determine which (if any) sides are squares;
// print out how many square sides there are
// The first is 2 x 3 x 4 (l x w x h)
// For the 2nd one, add 2 to the length and the width of the first one.
how do i even go about doing this?
View 1 Replies
View Related
Oct 10, 2013
I am supposed to create a class of rectangular prism in opengl. I am having touble in writing my "draw()" function.
I have searched the web, and lots of the sites have:
glBegin(GL_Quads);
glVertex3f(x,y,z);
glVertex3f(...);
glVertex3f(...);
glVertex3f(...);
3D coordinates for each face.
For my code, I am getting a value for lengths of x, y and z like "getXlength(x_length)" etc... I would like to know how I can use these values to draw the prism rather than giving values for each coordinates in each face.
View 1 Replies
View Related
May 31, 2014
I wrote a little program. I'd like to calculation of rectangular area. How can I add data to the console?
Code:
#include <iostream>
using namespace std;
class Teglalap {
protected:
double hossz;
double szelesseg;
double terulet;
[Code] ....
But it is wrong. Nothing happen. Which line is wrong?
View 2 Replies
View Related
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
May 24, 2013
How would i calculate a surface that up to 10^5 squares cover. The info you get is xpos,ypos and width for each square.
How would you calculate the total surface covered (if any overlap only one counts).
Cannot use a big array of bools as the memory limit is 512 MiB.
View 2 Replies
View Related
Jan 30, 2014
I am having trouble with calculating the volume of a cone
Assignment: Using the knowledge you already have, create, build, run, and correct if necessary a program that will calculate the volume of a cone. Insert into your code values for diameter of the base and the height. Use variables, constants, literals, and mathematics as necessary.
The formula for the volume is:
1/3 π x Radius2 x Height
Hint: you will need to add to your program two lines where appropriate:
#include <cmath>
const double PI = 2*acos(0.0);
Here is my current code:
#include <iostream>
using namespace std;
int main () {
//diameter of the base
float diameter = 3;
[Code] ....
View 3 Replies
View Related
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
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
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
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
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
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
View Related
Mar 14, 2014
So, I've used int to float cast before. And it makes sense that it preserves the int value just converts it. I don't really need the answer, I'm just interested, and a resources could suffice.
1. Why in my test program it seems to preserve the int value, I expect that, but why for 0x8000 is it registering bit negation also. I know that is the negative bit for float, but it seems wrong. Is this an error in the gcc compiler conversion code?
2. What is the documentation on these type cast on how they actual work.
3. I know like no assembly, I'm wondering if some of the built in routines to handle or is it all c side code.
4. Can I convert type and preserve the bits. Maybe use void* casting ? I've never really bothered with void* so I don't all that I can do. Except be a pointer that doesn't know the type, obviously. I tested that out in the second code, the output doesn't seem correct, except -0.000. Is it working and my test numbers just are improper float format? It can't be that I test 0x3E20000 = 0.15625 from SingleWiki , but I got 1.328e-36 so the int to void* to float doesn't seem to work in the code below:
#include <cstdio>
int main(){
float flout;
unsigned int num = 1;
int ant;
printf("Int Shift float");
for(unsigned int shift=0;shift<32;shift++){
[Code] ....
View 5 Replies
View Related
Feb 13, 2014
I want to make an encapsulated surface class that keeps track of important aspects about a surface. I have it started, except when I test the .onDraw() function, nothing appears on the screen. My Code is below:
#include "NSurface.h"
NSurface::NSurface() {
surface = NULL;
}
NSurface::~NSurface() {
SDL_FreeSurface(surface);
[code]....
why nothing is blitting to the screen when I test that class.onDraw() and SDL_Flip(screen)?
View 1 Replies
View Related
Apr 21, 2014
I am trying to write udf for heat flux on X-Y plane in Fluent having the formula
Q(Y) = (0.304)/(deltaY + deltaY/2)^-3
Where deltaY = 50cm and
Y = 10m
but I am unable to do it. Can write udf for heat flux? Y is the length on Y-axis and X whixh is equal to 5m is length on X-axis. Q is heat flux goes through X-Y plane in Z direction. Geometry is a cube with dimension 10*5*0.005 all are in meters.
View 1 Replies
View Related
May 28, 2013
Been trying to figure out why my program freezes. I know exactly what line of code is causing it, but I can't figure out WHY it's causing it. It compiles fine, there are no errors returned, and then the game just stalls and I have to ctrl+alt+del to kill it.
Anyway, what I have set up is something like this:
main.cpp
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "SDL_image.h"
#include "SDL_rotozoom.h"
[Code]....
This is the line of code that's freezing the program. Simply put, so that you don't really have to go through it piece by piece, what I have done is:
*each player gets their own drawing surface called PlayScreen
*each player gets an array of 360 drawing surfaces called ShipPic. These are to keep the game from having to render the rotation pics of the ship on the fly.
*Get_Ship clips the requested ship picture out of the ship sprite sheet and puts it in ShipPic[0] for the original angle.
*the original picture is rotated by 1 degree and put into the 360 ShipPic slots.
*when the player rotates their ship, the angle changes, and it calls the ShipPic with the same number as the player's angle and places it on the screen.
All of this works perfectly.
Then, in Player::draw_screen(), I have it set up so that each player looks at all the other players and gets their distance. If they're within range, it takes the other player's picture rotated by the other player's angle and puts it on the current player's PlayScreen. This is where it freezes.
I've checked for NULL pictures, I've checked to be sure the angle is between 0 and 359, nothing makes any difference. I know it's reading the other player's information since I can output all of the player's X & Y coordinates, angles, the width/height of their pictures, etc. on each other's screens. So they're definitely talking.
To test the code, I've changed it from
Apply_Surface(ShipX, ShipY, p[i].ShipPic[(int)p[i].angle], PlayScreen);
to
Apply_Surface(ShipX, ShipY, p[ID].ShipPic[(int)p[ID].angle], PlayScreen);
And it works perfectly, placing the player's OWN picture in for the other players. So the function works. It's just when I try to take another player's picture and place it on the current player's screen that it freezes.
I've tried quite a few different ideas, such as creating a temp drawing surface to blit the other player's picture onto, but again, it freezes as soon as I try using the other player's pictures.
View 5 Replies
View Related
Feb 22, 2015
n the requirements it says this;
-create a get and set for height, width, length.
-A default parameterized constructor = 1
-A method to resize the box
-A method to get the volume of the box
-A method to convert the object to a string
My Questions:
The 3 parts I am confused by are the default parameter constructor, the re-size the box and the method to convert to string. For the default parameter part I figured making length, width and height = to 1 would work, but I'm pretty sure thats not what I'm supposed to do.
This is the main file
#include "box_class.h"
#include <iostream>
using namespace std;
int main() {
double length;
double width;
double height;
double volume;
[Code] ......
View 1 Replies
View Related
Feb 27, 2013
I run some computations which give a big number of vectors (let's say 100 vectors, each one contain 2000 elements of type double). I want to save those data and import them into Excel.
I know I can save the results through in txt file. But it would be a very long file. Can I save the results in other more efficient file form that can be imported into Excel? and how?
View 7 Replies
View Related
Nov 6, 2014
I'm working on below program and I want the program to do the same thing, but with not one main() function, but instead one main() function PLUS one user defined function called computeConeVolume that contains the calculation. In other words I want to remove the one line calculation and replace it with a function call, then write and add the function below main with the calculation, surrounded any other syntax that I need to complete it.
The function should contain local variables and a constant declared and must have the calculation, it may not do anything else such as input or output. Should be able to declare "global" variables anywhere but no variables above or outside of main() and the function are allowed. A value-returning function should be used because it's a little simpler to understand, but you can employ a void function. Need to have a function prototype at the top of the code, then main, then your function.
//Cone Volume Calculator Program
#include <iostream>
using namespace std;
int main( ) {
//Declare variables and constants
double coneRadius = 0.0;
double coneHeight = 0.0;
[Code] ....
View 6 Replies
View Related
Apr 4, 2013
// DEBUG3-4
// This program contains a class for a cylinder
// Data members are radius and height
// The volume is calculated as pi times radius squared times height
// If no height is given, it's not a cylinder - it's a circle!
#include<iostream>
using namespace std;
//declaration section
[Code].....
View 1 Replies
View Related
Feb 5, 2014
What I want to do with my program is I want my length, width,volume and price to accept number values only. This is what I have so far.
// This program calculates and displays the pool's volume
// the amount of water needed and the cost.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// the double type accepts numbers including fractions for the following inputs.
double length, width, depth, poolvolume, watervolume, price;
[Code] .....
View 1 Replies
View Related
Mar 30, 2014
I need a line of code of retrieving data from a live website. I will look around in the mean time. libcurl?
View 1 Replies
View Related
May 3, 2013
In 2D I checked to see if a point was inside a shape by creating triangles between 2 neighbouring points and the centre of the object, then checking the angle to the 3 points from the test point and if the sum = 360... If not then it isn't inside the triangle. But how would I check if a point is inside a volume rather than an area? I know the same method would work but I don't think very well as it'll be testing with the thickness of the shell of the 3D object, which may be quite easily jumped in a single frame of movement..
View 8 Replies
View Related