GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 14-Jun-2012, 08:09
faithword faithword is offline
New Member
 
Join Date: May 2012
Posts: 5
faithword is on a distinguished road

Re: Two or more data types in declaration error


Quote:
Originally Posted by Mexican Bob
Does any body know what the assignment is? The assumption that it must calculate the area of various shapes is fairly obvious, but are there any "rules" or other requirements?

The code presented here is not horrible, considering that it is from someone just learning the language, but it is fairly awful. I'd suggest that you look at it as an example of what not to do.


MxB

Here are the requirements:

Write a program to prompt the user for a shape code. Read the shape code from the keyboard. Based on the shape code entered, prompt for the measurement(s) needed to calculate the area for that shape. Read the measurement(s) from the keyboard. Calculate the area of the shape. Print the area on the monitor. Allow the user to continue entering shape codes and values until he/she indicates no more processing is required. When the user does not want to continue, print a closing message.

Print an overview of the program's purpose. This should be in terms a user would understand. Make sure this is printed only once per program execution. Place this code in a function and call this function from main.

Write at least three other functions which are called from main. Examples of possible functions: get user input, calculate area for a shape, print output. Make at least one function receive an argument or arguments and at least one function return a return value other than 0 or void using the return statement. (It can be the same function.) The function that returns a value must have that value used by the calling function. One function must use a reference argument that is modified in the called function and then used in the calling function. Do not use any global variables.

Using a while or do-while loop, read the input, calculate the area, and print the output until the user decides to quit. Ask the user after printing the output if he/she wants to continue. After the user indicates he/she wants to quit, print a closing message.

Print the valid geometric shape codes as a "menu". Prompt the user for a valid geometric shape. Do not continue the program until a valid value is entered. The program will only calculate area for a square, a circle, or a rectangle. You may use the following codes for the shapes: C for Circle, S for Square, R for Rectangle. Make sure the information the user sees in the prompt explains clearly what the expected values are. Allow the user to enter the code in lower or upper case. That is, both c and C should be acceptable entries for circle.

If the user wants the area of a square calculated, prompt for the length of one side. Calculate area with the formula of area = length * length. If the user wants the area of a circle calculated, prompt for the circle's radius. Calculate area with the formula of area = PI * radius * radius. If the user wants the area of a rectangle calculated, prompt for the rectangle's length and width. Calculate area with the formula of area = length* width. Use a symbolic constant for PI and set its initial value to 3.14159.

Print the calculated area to a precision of 2 numbers after the decimal point.

You may not use any global variables except for symbolic constants.





  #12  
Old 14-Jun-2012, 08:19
faithword faithword is offline
New Member
 
Join Date: May 2012
Posts: 5
faithword is on a distinguished road

Re: Two or more data types in declaration error


Quote:
Originally Posted by Mexican Bob
Does any body know what the assignment is? The assumption that it must calculate the area of various shapes is fairly obvious, but are there any "rules" or other requirements?

The code presented here is not horrible, considering that it is from someone just learning the language, but it is fairly awful. I'd suggest that you look at it as an example of what not to do.


MxB

This what I have so far and cannot get it to loop properly if an invalid input is entered.

CPP / C++ / C Code:
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>


using namespace std;

void functionfrommain ();

void getUserInput (char& Y);

void validshapes ();

void areacalculations (char& S, char& C, char& R, double& length, double& radius, double& lengthtwo, double& width);

int main(int argc, char *argv[])
{
	char Y = Y;
	char S = S;
	char C = C;
	char R = R;
	const double PI = 3.14159;
	double length; double radius; double lengthtwo; double width;

	functionfrommain ();

	//do
	//{

	//double length = 0;
	//double radius = 0;
	//double lengthtwo = 0;
	//double width = 0;

	getUserInput (Y);

	if (Y == 'Y' || Y == 'y')
	{
	validshapes ();

	areacalculations (S, C, R, length, radius, lengthtwo, width);


	}

	else
	{
	cout << "Thank you for using the Area Calculator Service." << endl;
	}

	//while ((Y == 'Y' || Y == 'y')); 

	system("PAUSE");
	return EXIT_SUCCESS;
}



void functionfrommain ()
{

	cout <<"This program the area for a user specified geometric " << endl;
	cout << "shape. You will be asked to enter a code representing the shape. " << endl;
	cout <<"Depending on your choice,the program will prompt you for " << endl;
	cout <<"additional information necessary to calculate the area. " << endl;
	cout <<" " << endl;

	cout <<"You will be asked if you want to enter <more> data. " << endl;
	cout <<"Follow the directions provided to either stop the program or continue." << endl;
	cout <<" " << endl;


	cout << "Do you want to <enter> more data ?" << endl;
}

void getUserInput (char& Y)
{
	cout << "Enter Y to continue anything else to stop: ";
	cin >> Y;
	cout << " " << endl;
}

void validshapes ()
{
	cout << setw(5) << "-- VALID SHAPES --" << endl;
	cout << setw(5) << "Enter S for square" << endl;
	cout << setw(5) << "Enter C for circle" << endl;
	cout << setw(5) << "Enter R for rectangle" << endl;
}

void areacalculations (char& S, char& C, char& R, double& length, double& radius, double& lengthtwo, double& width)
{
	const double PI = 3.14159;
	char answer;

	bool bRepeat;

	do
	{
	bRepeat = false;

	cout << "Enter the proper letter : ";
	cin >> answer;


	if (answer == 'S' || answer == 's')
	{
	cout <<"Enter the length of 1 side of the square: ";
	cin >> length;
	cout <<"The area of your square is : " << length*length << endl;
	cout << setiosflags(ios::fixed)
	<< setprecision(2);
	}
	else if (answer =='C' || answer == 'c')
	{
	cout <<"Enter the radius of the circle : ";
	cin >> radius;
	cout <<"The area of your circle is : " << PI*radius*radius << endl;
	cout << setiosflags(ios::fixed)
	<< setprecision(2);
	}
	else if (answer =='R' || answer == 'r')
	{
	cout <<"Enter the length of the rectangle : ";
	cin >> lengthtwo;
	cout << "Enter the width of the rectangle : ";
	cin >> width;
	cout << "The area of your rectangle is : " << lengthtwo*width << endl;
	cout << setiosflags(ios::fixed)
	<< setprecision(2);
	}
	else
	{
	cout << "Invalid input " << answer << ". Please reenter" << endl;
	bRepeat = true;
	}
	}

	} while (bRepeat);
 
 

Recent GIDBlogRunning Linux Programs at Boot Time by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling C btrieve programs in VS 2005 emanresu C Programming Language 1 16-Nov-2009 03:19
Error C2143: syntax error : missing ';' before '.' kiranpreddy05 MS Visual C++ / MFC Forum 1 05-Nov-2009 07:39
Memory leak when nothing is happening... How can I even debug this ? Algar MS Visual C++ / MFC Forum 10 19-Nov-2007 07:17
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 11:25
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:57.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.