PDA

View Full Version : First C++ Class



HyperSecret
01-26-2009, 06:28 AM
/**
* @file Assignment2.cpp
* @description Enter Integer 1&2. Calculates the sum,
difference, product and average of the 2
Integers.
* @course CSCI 123 Section 14102
* @assignment 2
* @date 8/25/2008
* @author Derek Mardian (01146672) derekmardian@hotmail.com
* @version 1.0
**/

#include <iostream>
using namespace std;

int main() {

double inputOne;
double inputTwo;
int inputSum;
int inputDif;
int inputProduct;
double inputAverage; //operation variables

cout << "Enter Integer 1 : ";
cin >> inputOne;

cout << "Enter Integer 2 : ";
cin >> inputTwo;

inputSum = inputOne + inputTwo;
inputDif = inputOne - inputTwo;
inputProduct = inputOne * inputTwo;
inputAverage = (inputOne + inputTwo)/2;

cout << "Integer 1 + Integer 2 = " << inputSum << endl;
cout << "Integer 1 - Integer 2 = " << inputDif << endl;
cout << "Integer 1 * Integer 2 = " << inputProduct << endl;
cout << "Average of Integer 1 & Integer 2 = " << inputAverage << endl;

/* It outputs a decimal value for the Average because the two
* integers that you input are stored as doubles (0.00) with decimals.
* Average is also a double variable so it stores the integers that are
* already converted to decimals and outputs them as decimal numbers
* (doubles) also. */

return 0;
}


So yea this is pretty basic for most that will rate/hate this but let me tell you what I have learned so far in this class.


\n or endl; - newline
long, float, double, bool, int, etc... - variables
<< >> - insertion operators
cin - from screen to computer (input)
cout - from computer to screen (output)
/* */ and // - not compiled, notes
return 0 - terminates program

You only need 1 cout for every statement meaning you can do



cout << "line 1\n"
<< "line 2\n"
<< "line 3\n";


That will work just like putting cout infront of each line.
A ';' ends a statement. A line of code is considered a statement (above is 1 statement).

Mainly that is the main stuff we have learned so far in the class pertaining to C++ directly. We have gone through a couple different program we have to use for putting our files on the server at the campus and we spent too much time on that in my opinion.

There is obviously more we went over in class the basics of what a string, integer etc... is and what values they hold and how the computer reads them (bits, bytes, etc...). We also had to start at the bare basics that " " declares a string etc... since this is a intro class.

The class is going to start picking up this next week and should be learning more. Hopefully I can keep this going and be more in depth in the future to make a little 'Beginners' tutorial. Will start with lesson 1 "Hello World" when I have time.

Feedback?

Capricorn
01-26-2009, 06:37 AM
You were learning variables, so I am going to guess the assignment was to use variables for all the calculations right? Either way I hope you enjoy Computer Sciences.

HyperSecret
01-26-2009, 06:53 AM
The class is 'Intro to programming in C++' and you don't need any previous programming experience. So we have to go over the absolute basics. So the first week or two may be a little dull for me but oh well. Enjoy learning it even though I know most of it already.

Even though I never could make a hello world app and now I can.