![]() | |
| |||||||
| Register | iSpy | Wiki | All Albums | gXboxLive | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Welcome to the FinalGear.com Forums! | |
| This is the place to discuss everything related to Top Gear, Fifth Gear, and more! However, to gain full access to these forums, you will need to register. As a registered member, you will be able to:
All this and much more is available to you absolutely free when you register for an account, so sign up today! If you have any problems with the registration process or logging into your account, you can contact us. Already have an account? Login to the upper-right to hide this message and all advertisements on the forums. | |
| Technology Computers, gadgets and everything else. |
![]() |
| | LinkBack | Thread Tools | Search this Thread |
| | #1 | |
| Joined: Dec 1st, 2004 Last Online: Yesterday Location: ohio, usa Posts: 1,248
Car: 240, audi 5000, soon to be 240#2 Rep Power: 0 ![]() | i need some help with my homework. i need to use arrays to store multiple values for inputs and display the results in a table format. this is what i have so far. i missed this class due to doctors appointment and my professor is a dumbass and cant even do it. Quote:
__________________ | |
| | |
| | #2 |
| Global Moderator | UGH, basic *goes and have a shower, hoping it is still early enough to prevent contamination* |
| | |
| | #3 |
| OMFG I love Basic. I had it on a Vtech laptop when I was only a little nipper. Unfortunately that was about 10 years ago so I can't help you.
__________________ | |
| | |
| | #4 |
| I never messed with BASIC. I stick with web languages like php/mySQL/javascript
__________________ ![]() A man named Jeffy once said, "If laziness is craziness, then I've lost my marbles...and I don't feel like trying to find them." | |
| | |
| | #5 |
| .sa = bad driver! | Basic is great if it's on a platform with a lot of built-in functions, like a graphing calculator, because you can make useful, small, and simple programs very quickly. For anything else, run away. Run very far away. Learning Basic to make complicated programs will just teach you bad habits and make you used to writing spaghetti code. I suggest learning C or C++ first. They're low-level enough that the hardware is fairly exposed to you, and you're forced to do some memory management, which is a good learning experience. They're high-level enough though, that you focus on making functions rather than spaghetti code, and C++ will teach you how to make good object-oriented code (and if you want to learn programming, you MUST learn how to make good OO code!). Then later on you can learn a language like Python or Java, or one of the scripting languages. Here's what your code would look like in C++: (EDIT: Fixed the error Adunaphel noticed, but with const instead of #DEFINE )Code: #include <iostream.h>
#include <stdlib.h>
/* Name -
Date -
Program Name -
Program Description:
This Program will calculate the circle area, circumference, volume, and surface area of a cylinder
*/
//Constants
const double PI = 3.141592654;
//Function declarations
double circle_circumference(double radius);
double circle_area(double radius);
double cylinder_area(double radius, double height);
double cylinder_volume(double radius, double height);
//Main loop
int main()
{
double r, h, circumference, area, surface_area, volume;
int run_times, i;
// BEGIN WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK
system("CLS");
// END WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK
// Explain the program to the user
cout << "THIS PROGRAM WILL ALLOW THE USER TO ENTER THE NUMBER OF" << endl;
cout << "TIMES THE PROGRAM WILL RUN; OBTAIN THE NECESSARY" << endl;
cout << "DIMENSIONS FROM THE USER; CALCULATE THE VOLUME AND" << endl;
cout << "SURFACE AREA OF THE CYLINDER; AND DISPLAY THE RESULTS" << endl;
cout << "OF THE CALCULATIONS." << endl << endl;
do
{
cout << "How many times would you like to run the program? ";
cin >> run_times;
if (runtimes < 1)
{
cout << "Incorrect response, try again" << endl;
}
}
while (run_times < 1);
for (i = 1 ; i <= run_times ; i++)
{
// Get the input from the user
cout << "\n Enter the radius of the cylinder: ";
cin >> r;
cout << "Enter the height of the cylinder: ";
cin >> h;
// Calculate the info
circumference = circle_circumference(r);
area = circle_area(r);
surface_area = cylinder_area(r,h);
volume = cylinder_volume(r,h);
// Print the answers
cout << "The area of the base of the cylinder is " << area << ".\n";
cout << "The circumference of the base of the cylinder is " << circumference << ".\n";
cout << "The surface area of the cylinder is " << surface_area << ".\n";
cout << "The volume of the cylinder is " << volume << ".\n\n";
}
return 0;
}
//Functions
double circle_circumference(double radius) {return 2*PI*radius;}
double circle_area(double radius){return PI*radius*radius;}
double cylinder_area(double radius, double height){return (2*PI*radius*radius + 2*PI*radius*height);}
double cylinder_volume(double radius, double height){return PI*radius*radius*height;}
Code: #include <iostream.h>
#include <stdlib.h>
/* Name -
Date -
Program Name -
Program Description:
This Program will calculate the circle area, circumference, volume, and surface area of a cylinder
*/
//Constants
const double PI = 3.141592654;
//Function declarations
double circle_circumference(double radius);
double circle_area(double radius);
double cylinder_area(double radius, double height);
double cylinder_volume(double radius, double height);
//Main loop
int main()
{
double r, h, circumference, area, surface_area, volume;
char repeat;
// BEGIN WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK
system("CLS");
// END WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK
// Explain the program to the user
cout << "This program calculates the volume and surface area of a cylinder, as well as the area and circumference of its base. You can run as many different calculations as you like.\n\n";
do
{
// Get the input from the user
cout << "\n Enter the radius of the cylinder: ";
cin >> r;
cout << "Enter the height of the cylinder: ";
cin >> h;
// Calculate the info
circumference = circle_circumference(r);
area = circle_area(r);
surface_area = cylinder_area(r,h);
volume = cylinder_volume(r,h);
// Print the answers
cout << "The area of the base of the cylinder is " << area << ".\n";
cout << "The circumference of the base of the cylinder is " << circumference << ".\n";
cout << "The surface area of the cylinder is " << surface_area << ".\n";
cout << "The volume of the cylinder is " << volume << ".\n\n";
// Ask if they'd like to do it again
cout << "Would you like to do another calculation? (y/n) ";
cin >> repeat; // We just want the first letter
cin.ignore(80,'\n'); // Discard the rest, i.e. "es" or "o"
}
while (repeat == 'y' || repeat == 'Y');
return 0;
}
//Functions
double circle_circumference(double radius) {return 2*PI*radius;}
double circle_area(double radius){return PI*radius*radius;}
double cylinder_area(double radius, double height){return (2*PI*radius*radius + 2*PI*radius*height);}
double cylinder_volume(double radius, double height){return PI*radius*radius*height;}
__________________ "Shit, that's a busy table cloth." -matt2000 Last edited by chaos386; November 30th, 2006 at 10:09 AM.. |
| | |
| | #6 | |
| Lazy Head Dude | Quote:
PHP Code: ![]()
__________________ Fight back against the evil Quiky by +1'ing this post! There is no replacement for displacement. - Wolfgang Bernhard, Chief Operating Officer, Chrysler Group talking about the Dodge Viper SRT-10 ... I ask Herb Helbig, vehicle synthesis manager for SRT and a member of the original Team Viper development group since day one, if they'd ever thought of adding traction control. "It comes with two," he says, pointing at my feet. "Learn to use them." Got it. - Motor Trend on the 2006 Dodge Viper Coupe, November 2005 | |
| | |
| | #7 |
| My version is in Java ![]() I need to learn basics of Java for a data types & algorithms exam. It only runs once and there might be some bugs. Code: /*
* Cylinder.java
*
* Created on 29. marraskuuta 2006, 23:02
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author Tuomas
*/
public class Cylinder {
public static double R, A, SA, C, V, H;
/* Calculation functions
*/
public static void calcArea() {
A = Math.PI *R*R;
}
public static void calcCircumference() {
C = Math.PI *R*2;
}
public static void calcVolume() {
V = A*H;
}
public static void calcSurface() {
SA = C*H;
}
/* Main starts here
*/
public static void main(String args[])
{
System.out.println("THIS PROGRAM WILL ALLOW THE USER TO ENTER THE NUMBER OF\nTIMES THE PROGRAM WILL RUN; OBTAIN THE NECESSARY\nDIMENSIONS FROM THE USER; CALCULATE THE VOLUME AND\nSURFACE AREA OF THE CYLINDER; AND DISPLAY THE RESULTS\nOF THE CALCULATIONS.");
/* Input the variables
*/
Scanner input = new Scanner(System.in);
System.out.println("Enter the radius of the cylinder: ");
R = input.nextDouble();
System.out.println("Enter the height of the cylinder: ");
H = input.nextDouble();
input.close();
/* Using the calc-functions to calculate
*/
calcArea();
calcCircumference();
calcVolume();
calcSurface();
System.out.println("Area: " + A + "\nCircumference: " + C + "\nVolume: " + V + "\nSurface Area: " + SA);
}
}
__________________ This space has been reserved. | |
| | |
| | #8 |
| Lazy Head Dude | That makes 3 solutions now in languages other than the one he wanted. Too funny.
__________________ Fight back against the evil Quiky by +1'ing this post! There is no replacement for displacement. - Wolfgang Bernhard, Chief Operating Officer, Chrysler Group talking about the Dodge Viper SRT-10 ... I ask Herb Helbig, vehicle synthesis manager for SRT and a member of the original Team Viper development group since day one, if they'd ever thought of adding traction control. "It comes with two," he says, pointing at my feet. "Learn to use them." Got it. - Motor Trend on the 2006 Dodge Viper Coupe, November 2005 |
| | |
| | #9 |
| .sa = bad driver! | ^Your area calculation doesn't seem to be multiplying by pi. I like how we've translated his program into three other languages, but have completely forgotten his original question, which is how to use arrays and tables in Basic. ![]()
__________________ "Shit, that's a busy table cloth." -matt2000 |
| | |
| | #10 |
| how you guys can write those programs amazes me, I struggled with Basic MATLAB , and I'm going to have to do Java next semester, I'll prob. be posting in this thread quite alot ![]()
__________________ | |
| | |
| | #11 |
| Lazy Head Dude | I totally fucked up the radius to the 2nd power part (never done a power in PHP before) and I stupidly used "(int)" to make the input a number forgetting that that would make it an integer. Here it is all fixed. ![]() Oh, and chaos386 also pointed out to me that you forgot to add the area of the ends to get the total surface area (I just copied your math). Fixed it in my script though. PHP Code:
__________________ Fight back against the evil Quiky by +1'ing this post! There is no replacement for displacement. - Wolfgang Bernhard, Chief Operating Officer, Chrysler Group talking about the Dodge Viper SRT-10 ... I ask Herb Helbig, vehicle synthesis manager for SRT and a member of the original Team Viper development group since day one, if they'd ever thought of adding traction control. "It comes with two," he says, pointing at my feet. "Learn to use them." Got it. - Motor Trend on the 2006 Dodge Viper Coupe, November 2005 |
| | |
| | #12 |
| BASIC ruled. I wrote an ASCII snake game in qbasic for dos ages ago. Started writing an rpg too, got the graphics working but couldn't quite get it running smoothly and lost interest. When is this in for? Writing a report at the moment so won't have time till friday at earliest. Hopefully you'll decipher one of the above ok!
__________________ Currently Drive - 205 GTI Currently Want - 1967 Mustang GT500 (Eleanor!) | |
| | |
| | #13 |
| I use Visual Basic at school, I'm OK at it but wish we used the newer one, the old one is so Windows 98. Are there any sits that can teach you to get better at it? | |
| | |
| | #15 |
| Joined: Jun 7th, 2004 Last Online: 12:11 AM Location: Wales, UK Age: 22 |