 Status
Not open for further replies.
1 - 3 of 3 Posts

#### Cwwoods

·
##### Registered
Joined
·
4 Posts
Discussion Starter
Hello All,

It's my first time on the forum but I hope to become a valued member in the future. The reason for my post is that I enrolled in my first C++ programming class this semester and I am having a bit of trouble. I have emailed my professor for help and even attempted to find a tutor but no one has the time it seems. Since it is my first class I am a "novice" in every since of the word so I apologize if I am any trouble.

The assignment he gave the class is as follows:

(Related to arrays)

Write a function that will calculate the circumference of a polygon.

(I'm assuming that the distance formula will be used here ..length of segment blah..blah)

Write another function that will calculate the area of a polygon.

(which is y sub 0 * delta x + 1/2 * delta x * delta y)

or at least he said that was the formula for concave as well as convex*shrugs

we must allow for up to 20 coordinates.

This is what I have so far:

#include <iostream>
#include <iomanip>
#include <cmath>

using std::cout;
using std::cin;
using std::endl;
using std::setw;

int arrayx; //array's containing x,y coordinates
int arrayy; //array's containing x,y coordinates
float polycirc; // hold value "circumference of polygon"
float polyarea; // hold value "area of polygon"
int option = 0;

int main()

{

//testing values cout << polycirc << polyarea << option << endl;

cout << "1. Enter the polygon\n" << endl;
cout << "2. Calculate the circumference of the polygon\n" << endl;
cout << "3. Calculate the area of the polygon\n" << endl;
cout << "4. Exit\n" << endl;

while ((option = cin.get()) != 0 )

switch (option)

{ //start switch

case '1':

cout << "Enter a polygon\n";

break;

case '2':

cout << "Calculate the circumference of the polygon\n";

break;

case '3':

cout << "Calculate the area of the polygon\n";

break;

case '4':

cout << "Good Bye!\n";

return 0;

break;

case ' ':

break;

case '\n':

break;

case '\t':

break;

default:

cout << "Please enter another option\n";

break;

} //end switch

return 0;

}

Any help would be greatly appreciated ... the assigment is due wednesday the 19th.

Thanks a bunch

Chris

#### Cwwoods

·
##### Registered
Joined
·
4 Posts
Discussion Starter
Updated Code

I have changed it to this so far.... I couldn't figure out how to edit my post again :sad:

#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{

int option;

while(option != 6)

{
option = 0;

while(option < 1 || option > 6)
{
cout<<"1. Enter a polygon" << endl;
cout<<"2. Calculate the circumference of the polygon" << endl;
cout<<"3. Calculate the area of the polygon" << endl;
cout<<"4. Did you know? (M*A*S*H trivia)" << endl;
cout<<"5. More Trivia" << endl;
cout<<"6. Exit program" << endl;

cout << endl << "Option ?";

cin >> option;

if(option < 1 || option > 6)
{
cout << "invalid responce choose again\n" << endl;
}
}

switch (option)
{
case 1:

cout << "Test1\n" << endl;

break ;

case 2:

cout << "Test2\n" << endl;

break ;

case 3:

cout << "Test3\n" << endl;

break ;

case 4:

cout << "In an episode where a Korean man is given a chocolate bar,\n the wrapper clearly has a barcode (introduced in the late 1970s).\n" << endl;

break;

case 5:

cout << "The characters drink beer from aluminum cans,\n which were not available until well after the 1950s.\n" << endl;

break;

case 6:

cout<<"program exit"<<endl;

break;
}

}

return 0;
}

#### Cwwoods

·
##### Registered
Joined
·
4 Posts
Discussion Starter
This is what I have so far 10/18

#include<iostream>
#include<cmath>
#include<fstream>
#include<iomanip>

using std::cout;
using std::cin;
using std::endl;
using std: ow;
using std::setw;

double distance(double, double, double, double);

double xone, yone, xtwo, ytwo, lineLength;

int polyCirc;

int main()
{

int option = 0;

while(option != 6)

{
option = 0;

while(option < 1 || option > 6)
{
cout<<"1. Enter a polygon" << endl;
cout<<"2. Calculate the circumference of the polygon" << endl;
cout<<"3. Calculate the area of the polygon" << endl;
cout<<"4. Did you know? (M*A*S*H trivia)" << endl;
cout<<"5. More Trivia" << endl;
cout<<"6. Exit program" << endl;

cout << endl << "Option ?";

cin >> option;

if(option < 1 || option > 6)
{
cout << "invalid responce choose again\n" << endl;
}
}

switch (option)
{
case 1:

int polyCirc;

for(int i = 0; i < 20 ; i++)
cin >> polyCirc;

cin >> xtwo;
cin >> xone;
cin >> ytwo;
cin >> yone;

lineLength = distance(xone, xtwo, yone, ytwo);

cout << lineLength << endl;

return 0;

//Test cout << x1 << y1 << x2 << y2 << endl;

break ;

case 2:

cout << "Test2\n" << endl;

break ;

case 3:

cout << "Test3\n" << endl;

break ;

case 4:

cout << "In an episode where a Korean man is given a chocolate bar,\n the wrapper clearly has a barcode (introduced in the late 1970s).\n" << endl;

break;

case 5:

cout << "The characters drink beer from aluminum cans,\n which were not available until well after the 1950s.\n" << endl;

break;

case 6:

cout<<"program exit"<<endl;

break;
}

}

return 0;
}

//////////////////////////////////////////////////////////////////
double distance(double xone, double xtwo, double yone, double ytwo)

{ // start function

lineLength = (sqrt(pow(xtwo - xone,2)) + (pow(ytwo - yone,2)));

return lineLength;

} // end function

why does this array yield 25 points?

1 - 3 of 3 Posts
Status
Not open for further replies.