Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 10-15-2005, 10:16 PM   #1 (permalink)
Registered User
 
Join Date: Oct 2005
Posts: 4
OS: XP Prof


Help with programming assignment

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[20]; //array's containing x,y coordinates
int arrayy[20]; //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

Last edited by Cwwoods; 10-15-2005 at 10:18 PM.
Cwwoods is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 10-15-2005, 11:22 PM   #2 (permalink)
Registered User
 
Join Date: Oct 2005
Posts: 4
OS: XP Prof


Updated Code

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


#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 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-18-2005, 09:05 PM   #3 (permalink)
Registered User
 
Join Date: Oct 2005
Posts: 4
OS: XP Prof


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::pow;
using std::setw;


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

double xone, yone, xtwo, ytwo, lineLength;

int polyCirc[20];


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:

cout << "Please enter your points." << endl;

int polyCirc[20];

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





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?
Cwwoods is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 06:25 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85