[spoiler title=”Lesson Video”]
Direct Download of Video(For mobile / offline viewing)(right click > save target as)

[/spoiler]

[spoiler title=”Lesson Source Code”]

#include 
#include 

using namespace std;

int main(){
  //Write a program that allows a user to enter three numbers, store the sum of them in a variable called total, then output the total.
  //Ex. Credit:  re-write that program without the total variable.

  //Variables -- int / long,  double / float, and string / char
  string str = "Hello World";
  cout < < "Str = " << str << endl;
  int myNumber = 75000; // Whole numbers only
  cout << "MyNumber = " << myNumber << endl;

  double myDouble = 5.5555;
  cout << "MyDouble = " << myDouble << endl;

  int userValue = 0;
  cout << "Please Enter a value: "; 
  cin >> userValue;

  cout < < "userValue = " << userValue << endl;

  cout << endl;
  system("PAUSE");
  return 0;
}


[/spoiler]

Download link for Visual Studio Express 2013 for Windows Desktop (This is needed to compile your code)

Homework is described and should be submitted here: https://beginnerscpp.com/forums/index.php/topic,51.0.html
–Hello World–
This lesson opened with an example of programming that’s literally as old as programming. Let’s look at the simplest program in C++ and then break it down into it’s parts.

#include
using namespace std;
int main(){

cout < < "Hello World" << endl;

return 0;
} //end main

#include
This line is telling the compiler that we’re going to be including a library called iostream. This library contains cout, cin, and a few other lesser-used input / output options for programs.


using namespace std;
This line tells the compiler that we’re going to be using items from the standard C++ namespace, this makes it so we don’t need to prepend std:: to commands like cin or cout.


int main(){
This line is fairly simple, it shows where the start of the “main” part of our program is. I want you guys to take special notice to the { though. That’s known as a Scope Bracket, these can make your life easier or harder based on the habits you develop with them now. You guys should use this as something of a rule when it comes to programming: “Every line I write should end with either a ; or an { or } . This will make your life much easier, especially in the early stages of programming.


cout < < "Hello World"<
This line calls the function “cout” from the iostream library, and passes in the text string “Hello World”. The part after that (endl) is just to make a new line after that. We’ll get more into how this works in subsequent lessons, or go here for more examples


return 0;
This line tells the compiler that it can “return” (to the command prompt) if everything went well. The return command will make more sense later. The reason we’re using return 0 and not some other number is because that means “The program exited normally” to most host OS’s.


} //end main
This is really just a closing bracket } , the //end main after it is what’s known as a comment. Comments are used by programmers to keep track of what’s what in a program. In this case when you have a longer program with many brackets, you might want to know that this bracket is closing your int main() opening bracket.

Concepts learned:

  • Including libraries (#include
  • Variables (type variableName)
  • Types (see below)
  • Initialization
  • Simple input / output

Types used:

int, long
These types are used to represent whole numbers.
double / float
These types are used to represent floating point values (numbers that may have decimal points).
string / char
String and char are two types that are used to represent letter and number values.

[spoiler title=”Lesson Video”]
Direct Download of Video (For mobile / offline viewing)(right click > save target as)


[/spoiler]

[spoiler title=”Lesson Source Code”]

#include 
#include 
 
using namespace std;
 
 
int main(){
  int userValue = 0;
  cout < < "Enter a value for userValue: ";
  cin >> userValue;
 
  cout < < "userValue = " << userValue << endl;
 
 
 
  system("PAUSE");
  return 0;
}

[/spoiler]

Camelback Notation
Camelback Notation is a naming scheme in which you use a lowercase word, and then capitalize every word thereafter. Some examples of phrases in camelback would be:

  • costOfItems
  • itemQuantity
  • purchaseOrders
  • customerFirstName
  • customerLastName
  • currentStreetAddress

[spoiler title=”Lesson Video”]
Direct Download of Video (For mobile / offline viewing)(right click > save target as)


[/spoiler]

[spoiler title=”Lesson Source Code”]

#include 
#include 
using namespace std;
 
 
int main(){
 
  // 1 + 3
  // i + j
  // +, -, *, /, %    -- % is remainder 10%3   10/3 then give me the remainder,  1
  //a, b ,c.   total = a+b+c;   total = 10;  total = total+a+b+c;  total += a+b+c;
  // +=, -=, *=, /=
 
  //Homework: Creating a simple interest calculator -- futureMoney = principle*(rate*time);
  //Creating a compound interest calculator
 
  int years = 0;
  double APR = 0.0, principal = 0.0, total = 0.0;
 
  cout < < "Enter your starting capital: ";
  cin >> principal;
 
  cout < < "\nEnter your APR (ex: 8.0% = 8):  ";
  cin >> APR;
 
  cout < < "\nHow many years will your invest this money for: ";
  cin >> years;
 
  APR /= 100;
  total = principal * (  pow((1+APR),years)  );
  cout < < "\nThe amount in your account after: " << years << " years will be: " << total << endl;
 
 
 
 
  system("PAUSE");
  return 0;
}

[/spoiler]

Homework is described and should be submitted here: https://beginnerscpp.com/forums/index.php/topic,55.0.html



Cmath
Cmath is a library that is used to perform mathematical functions in C++ programs. You could always create functions of your own to perform the tasks in this library (when you learn functions down the line). For a more complete listing of functions available inside the cmath library click here


Raising a number to a power
Raising a number to a power is very easy in C++ using the Cmath library. The reference linked above should show you examples. For powers you would use pow(number, powerRaisedTo); as your command.


[spoiler title=”Lesson Video”]
Direct Download of Video (For mobile / offline viewing)(right click > save target as)


[/spoiler]

[spoiler title=”Lesson Source Code”]

#include 
#include 
#include 
using namespace std;
 
 
int main(){
 
  // 1 + 3
  // i + j
  // +, -, *, /, %    -- % is remainder 10%3   10/3 then give me the remainder,  1
  //a, b ,c.   total = a+b+c;   total = 10;  total = total+a+b+c;  total += a+b+c;
  // +=, -=, *=, /=
 
  //Homework: Creating a simple interest calculator -- futureMoney = principle*(rate*time);
  //Creating a compound interest calculator
 
  int years = 0;
  double APR = 0.0, principal = 0.0, total = 0.0, total2=0.0, total3=0.0;
 
  //fixed -- Scientific notation 5 decimal places are always shown
  cout < < setiosflags(ios::showpoint) << setiosflags(ios::fixed); 
 
 
  cout << "Enter your starting capital: ";
  cin >> principal;
 
  cout < < "\nEnter your APR (ex: 8.0% = 8):  ";
  cin >> APR;
 
  cout < < "\nHow many years will your invest this money for: ";
  cin >> years;
 
  APR /= 100;
  total = principal * (pow((1 + APR), 1));
  total2 = principal * (pow((1+APR),2)  );
  total3 = principal * (pow((1 + APR), years));
 
 
  cout < < "Starting amount" << " | " << "Interest Rate" << " | " << "Years Invested" << " | " << "Final Amount" << endl;
 
  cout << setprecision(2) << "$" << principal << setw(10) << " | " << 1 + APR << "%" << setw(11) << "| " << 1 << setw(16) << "| " << total << endl;
  cout << setprecision(2) << "$" << principal << setw(10) << " | " << 1 + APR << "%" << setw(11) << "| " << 2 << setw(16) << "| " << total2 << endl;
  cout << setprecision(2) << "$" << principal << setw(10) << " | " << 1 + APR << "%" << setw(11) << "| " << years << setw(16) << "| " << total3 << endl;
 
 
  //cout << "\nThe amount in your account after: " << years << " years will be: " << total << endl;
 
  cout << "\n\n";
 
 
  system("PAUSE");
  return 0;
}

[/spoiler]



IOManip
In this lesson we covered iomanip (full listing of functions in library here: http://www.cplusplus.com/reference/iomanip/). The 4 functions that we set our sights on were

  1. showpoint (via setiosflags)
  2. fixed(via setiosflags)
  3. setprecision
  4. setw


Showpoint
Showpoint is an ios flag that forces the console to show the numbers after the decimal point. This is true even with integer numbers that do not have a decimal point


Fixed
Fixed is an ios flag that forces the console to show a certain amount of numbers after the decimal point


setprecision
Setprecision is a function that specifies the minimum precision (points after the decimal) you will allow it to print.


setw
Setw is a function used for formatting tables. It automatically adds a certain number of spaces. You can also change the fill using setfill (linked in the reference above)


[spoiler title=”Lesson Video”]
Direct Download of Video (For mobile / offline viewing)(right click > save target as)


[/spoiler]

[spoiler title=”Lesson Source Code”]


Source Code for this video needs transcription


[/spoiler]

Homework: https://beginnerscpp.com/forums/index.php/topic,59.0.html



Order of Operations
The order of operations in C++ is as follows:

  1. Parenthesis / Functions
  2. Multiplication / Division (left to right)
  3. Addition / Subtraction (left to right)

Therefore using these rules we can discern that C++ would resolve the following equation:

7+(6*3-2)*2
Would resolve to 39– 18-2 = 16*2 = 32 +7 = 39