![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| 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: * 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 |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#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. |
|
|
|
| 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 |
|
|
#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; } |
|
|
|
|
|
#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? |
|
|
|
![]() |
| Thread Tools | |
|
|