Você está na página 1de 3

C++ class example program

C++ class program example: In our code we create a class named programming with one variable and two functions. In main we create an object of class and call the functions using it.

C++ programming code


#include<iostream> using namespace std; class programming { private: int variable; public: void input_value() { cout << "In function input_value, Enter an integer\n"; cin >> variable; } void output_value() { cout << "Variable entered is "; cout << variable << "\n"; } }; main() { programming object; object.input_value(); object.output_value(); //object.variable; return 0; } Quote: Originally Posted by The Bartender Paradox I don't know C++ that well, but Going from acceleration and time to velocity and position are just a couple of simple algebraic equations in one dimension, and its not that hard to expand it to three. If your inputs for accel and time are just two numbers, then, assuming that both position and velocity are initially at 0: Velocity = Acceleration * Time Position= 1/2 * acceleration * (Time^2) Will produce an error because variable is private

If velocity and position are not initially 0 then Velocity = (Acceleration * Time) + InitialVelocity Position= (1/2 * acceleration * (Time^2)) + (InitialVelocity * Time) + InitialPos

// this method would compute the case of v0 = 0 double[] findPosition(double time, double acceleration){ } //this method would take care of the other case double[] findPosition(double time, double acceleration, double initialPos, double intialVelocity){ } // this method would compute the case of v0 = 0 double[] findPosition(double time, double acceleration){ } //this method would take care of the other case double[] findPosition(double time, double acceleration, double initialPos, double intialVelocity){ }

Writing A Basic C++ Program - Am I On The Right Track?


Oh My GOSH Please Say Yes! I Have To: Write a C++ program to determine a cars acceleration within 10 seconds. Read in the starting speed and the ending speed. Use the formula: The program should display the start speed, end speed, and acceleration in miles per second. OKAY - This is what I have: #include <iostream> using namespace std; int main() { const int ACCELERATION= 10; cout<< speed << speed = <<speed/ACCELERATION<< acceleration << endl; double sspeed, espeed, speed, acceleration; cout<< Enter start speed in mph: ; cin>> sspeed sspeed= (sspeed/1)/3600;

cout<< Enter end speed in mph: ; espeed= (espeed/1)/3600; speed= espeed-sspeed; acceleration= speed/ACCELERATION cout= The cars acceleration in m/s*2 is ; cout= acceleration; return 0; }

Você também pode gostar