BEFORE YOU START: The professor highly recommends you type these out, in this blog I quickly forgot that typing is also a good method of learning for beginner programmers, try typing the code and analyze it as you go. In this blog I suggest copy and paste but only do that if you are confident in learning the material in such a way.
Week 1
=Part A=
Step1:
Step One basically walks you step by step on how to create a new project to work on. Simply follow the steps one by one and you should be OK.
⦁ From the File menu, choose "New Project."
⦁ Choose “Win32 Console Application.”
⦁ Enter a name in the name field.
⦁ Click “OK”
⦁ Click “Next” and choose the following options:
⦁ Application Type: "Console Application"
⦁ Additional options: Check mark “Empty project”.
⦁ Click Finish. Your project is now created.
⦁ Choose “Win32 Console Application.”
⦁ Enter a name in the name field.
⦁ Click “OK”
⦁ Click “Next” and choose the following options:
⦁ Application Type: "Console Application"
⦁ Additional options: Check mark “Empty project”.
⦁ Click Finish. Your project is now created.
Step2:
After step1 you should have a project to work on but you don't have any code, and to write code you will need a source file (a file that contains your source code "The code you write"). Again this is a step by step process and simply following the steps, you should be fine.
⦁ In the Solution Explorer, right-click on the “Source Files” folder and select "Add" and then "New Item."
⦁ In the next dialog box, choose C++ file (.cpp), enter a name for your source code file, and press the Add button.
⦁ Type or copy and paste your code into the newly created source code file. Build the file by pressing F7, and then execute your program by pressing CTRL-F5 (start without debugging) or use the F5 key (Start Debugging).
At the end you will be asked to press F7 to build and then F5 to start debugging. Simple forget F7 and just press F5 as debugged actually builds the program in the process already. F5 is for debugging and as of yet in class we have yet to touch on that so I wont go into it.
⦁ In the next dialog box, choose C++ file (.cpp), enter a name for your source code file, and press the Add button.
⦁ Type or copy and paste your code into the newly created source code file. Build the file by pressing F7, and then execute your program by pressing CTRL-F5 (start without debugging) or use the F5 key (Start Debugging).
At the end you will be asked to press F7 to build and then F5 to start debugging. Simple forget F7 and just press F5 as debugged actually builds the program in the process already. F5 is for debugging and as of yet in class we have yet to touch on that so I wont go into it.
Step3:
The next part say to enter the following code EXACTLY as you see it:
#include <iostream>
using namespace std;
void main()
{
cout << "John Doe" << endl;
cout << "CIS170C - Programming using C++\n";
cout << "\n\n\nHello, world!\n\n";
}
but who has time to type that, simply copy and past it into your source file. You then have to change the name John Doe to your name, remember to leave the double quotes intact. Anything inside double quotes is considered a string, and a string is just a bunch of characters or if its easy its plain text. The next step says that the program will appear and disappear this is because once the program runs through all its steps it is complete and simply closes, you need to tell the program to not close and there are a number of ways to do this though simply typing system("pause"); will suffice apparently in this class and it looks easier to understand to beginners. So your code now should look something like this:
#include <iostream>
using namespace std;
void main()
{
cout << "YOUR NAME" << endl;
cout << "CIS170C - Programming using C++\n";
cout << "\n\n\nHello, world!\n\n";
system("pause");
}
Step4:
Simply states what the output should look like when you run the program (press F5 again).
John DoeThough this isn't true as you see in the code above there are multiple instances of \n which means NewLine. So in turn every time \n appears the cursor(blinking vertical line) should move down to the next line in the console(black box with white text in it), we also added the system("pause") so the actual output should look more like this:
CIS170C - Programming using C++
Hello, World
YOUR NAMETip: If you get a similar result to this, while the console or "command prompt" is selected Press Alt + Print-screen now and paste it into a new word document to be able to skip the repetitive steps later.
CIS170C - Programming using C++
Hello, world!
Press any key to continue . . .
Step5:
This part just tells you to save your project, but from my experience each time you debug it(press F5) the project is automatically saved, but in case I'm wrong just press Ctrl + S or what I do is press the little floppy disk in the top left corn of Visual Studios. There is also an icon what has two floppy disks, that is for saving projects with multiple source files etc, for the time being we are only working with only one source file but you can still alternatively press the double floppy icon.
Step6:
This again in my opinion is useless If you followed the tip from step4 skip this step if not continue reading. When debugging the program an executable is already generated so why is the purpose of building it again unless you have made some changes to the source file? it also goes on to mentions errors etc, if errors had come up it would have came up already in steps before this one, if you did get errors you have made recent changes. If you made no changes since last debug simply skip this step.
Step7:
Again we debug it but if you followed my Tip from Step4 you can skip this Step, if not shame on you and continue reading. Simply press F5 again to debug the program again.
Step8:
If you followed my tip from step4.....skip, if not read on. Having the console or "command prompt" selected press Alt + Print-screen. Open a new word document and paste into it.
Step9:
Copy the source code and paste it also into the same word document and save it with the following file name format: Lab01A_LastName_FirstInitial (keeping the underscores).
You are now done and can close Visual Studios or Visual C++.
Note: During submission the professor wants both the word document as well as the project files.
The project files are located in you "My Documents" or "Documents" folder depending on your version of the windows operating system. In there is a folder called either "Visual C++", "Visual Studios 2010" or "Visual Studios 2012". In there is a folder called "Projects" and in that folder is where you will find the project files for your programs you have made and/or are currently working on.
Visual Studios 2012 project to 2010 Conversion:
Open your solution file (*.sln) in notepad. Make 2 changes (the * means what ever file name)
- Replace "Format Version 12.00" with "Format Version 11.00" (without quotes.)
- Replace "# Visual Studio 2012" with "# Visual Studio 2010" (without quotes.)
Here is a video I found on YouTube of someone doing it:
=Part B=
Step1:
Simple Create a new project a source file like in PartA.
Step2:
Again we are lazy or what I'd rather consider myself efficient and copy the following source code into your source file.
// ---------------------------------------------------------------
// Programming Assignment: LAB1B
// Developer: ______________________
// Date Written: ______________________
// Purpose: Ticket Calculation Program
// ---------------------------------------------------------------
#include <iostream>
using namespace std;
void main()
{
int childTkts, adultTkts, totalTkts;
childTkts = 3;
adultTkts = 2;
totalTkts = childTkts + adultTkts;
cout << totalTkts << endl;
}
Change the Developer to your name and also set the date. The final result should look simething like this:
// ---------------------------------------------------------------
// Programming Assignment: LAB1B
// Developer: YOUR NAME
// Date Written: DATE
// Purpose: Ticket Calculation Program
// ---------------------------------------------------------------
#include <iostream>
using namespace std;
void main()
{
int childTkts, adultTkts, totalTkts;
childTkts = 3;
adultTkts = 2;
totalTkts = childTkts + adultTkts;
cout << totalTkts << endl;
}
// Programming Assignment: LAB1B
// Developer: YOUR NAME
// Date Written: DATE
// Purpose: Ticket Calculation Program
// ---------------------------------------------------------------
#include <iostream>
using namespace std;
void main()
{
int childTkts, adultTkts, totalTkts;
childTkts = 3;
adultTkts = 2;
totalTkts = childTkts + adultTkts;
cout << totalTkts << endl;
}
Step3:
Remember that awesome little floppy icon on the top left, yeah? well click it.
Step4:
Press F5.
Step5:
Skip it.
Step6:
Alt + Print-screen, Paste into a new word document along with the code and name it with the following format: Lab01B_LastName_FirstInitial (keeping the underscores).
All done.
=Part C=
Step1:
At this point I shouldn't have to tell you to make a new project and a new source file, it should come naturally like eating, pooping, peeing, sleeping, and hopefully showering, I mean the concept of soap and water isn't hard, neither should this.
At this point I shouldn't have to tell you to make a new project and a new source file, it should come naturally like eating, pooping, peeing, sleeping, and hopefully showering, I mean the concept of soap and water isn't hard, neither should this.
Step2:
Aws no copy and paste this time around, well TOO BAD we still gonna rock this assignment. Lets do it. Ok the task is to calculate and display some text and numbers in according to some everyday stuff.....yeah I don't know this crap because I still live in my moms basement.......Good thing there is an output sample and diagram provided that makes our lives that much easier....well at least on this assignment, though the sample is off from what the actual result is (we'll get into that later).
Enter Weekly Sales: 28000
Total Sales: 28000.00
Gross pay (7%): 1960.00
Federal tax paid: 352.80
Social security paid: 117.60
Retirement contribution: 196.00
Total deductions: 666.40
Take home pay: 1293.60
Press any key to continue . . .
But because I found that the Diagram was missing a step I edited it so its more clear and understandable to beginners.
uwww look at all the pretty shapes....we will be working on this one shape at a time. First the oval. The oval can be consider the step where you setup your project, including libraries and namespaces and the main function. So your project should the look something like this:
#include <iostream>
using namespace std;
void main()
{
}
PS: I will be using void main until the assignments switch over to int main.
The next part (first rectangle) is kind of misleading as I initially interpreted it as declaring everything as global. Global variables are variables that are outside functions and they can be accessed from anywhere else in your program, but for this simple program it doesn't really matter since we will only have one main function. Raise your hand if you think you know how to declare variables......put your hand down I can't see it anyways, if you know then skip this paragraph, if not read on. Variables are data and specific data at that. To declare a variable you first specify the type, for example you can use integer for whole numbers, string for plain text, boolean for a value that is true or false, float which is a decimal number to a specific decimal place, double which is like float but is more precise as it can store decimal numbers with more digits after the decimal place. Then the next thing is you want to give it a name, just like giving a name to a pet you will find that you will be calling this name to distinguish it from the rest. The thing about C++ is that it is cap sensitive and that means you can have variables with the same name but with different capitalization, for example TizzyT is not the same as tizzyt and is not the same as tiZZyt and not the same as....you get the idea. Lastly you can choose to give your variable an initial value, this is like mutant messenger pigeons that come once their names are called (smart ass pigeons), you can get a new pigeon, and not give it a message, but you will still have that pigeon to give a message to later on. So to recap variable are declared by first specifying type, then given a name, and then optionally given an initial value.
Here is a variable that is declared with no initial value:
int Hungry;
Here is a variable that is declared with an initial value:
int Bloated = 9000;
Also do not forget the semicolon as the end.
Now that we have that out of the way lets continue. the syntax in the box looks a lot like VB (another programming language) so converting it, one can use float or double in place of decimal. Do that for each variable, you should now have something like this:
#include <iostream>
using namespace std;
void main()
{
float weeklySales;
float grossPay;
float fedTax;
float socSecurity;
float retirement;
float totDeductions;
float takeHomePay;
}
Alternatively it can also look like this:
#include <iostream>
using namespace std;
void main()
{
float weeklySales,
grossPay,
fedTax,
socSecurity,
retirement,
totDeductions,
takeHomePay;
}
Now this part is where I added that extra rhombus thinga-mahjig, so that we don't have to work backwards later on like we would have to do if we followed the original diagram. Here we are basically asking the user for an input that is the number of sales he made in a week. For that we use cout which is short for C out, hehe pretty clever huh...no? oh wells moving on. We first use cout followed by << and then the text you want to display that is between two double quotes. Don't for get the semi colon, in this instance we are not using the endl because we still desire to work on the same line we are currently on. So the code you should have should look something like this:
#include <iostream>
using namespace std;
void main()
{
float weeklySales;
float grossPay;
float fedTax;
float socSecurity;
float retirement;
float totDeductions;
float takeHomePay;
cout << "Enter Weekly Sales: $";
}
Next is another rhombus looking du-hicky, It says "input weeklySales" where input means that the program is expecting the user of the program to put something in, and where weeklySales is the name of one of our smart ass pigeons I mean variables, basically its saying the user will assign a value to the variable named weeklySales. we do this with cin short for C in, get it? (hey writing this isn't exact fun you know) followed by >> and then the name of the variable weeklySales. Your code should look like this at this point:
#include <iostream>
using namespace std;
void main()
{
float weeklySales;
float grossPay;
float fedTax;
float socSecurity;
float retirement;
float totDeductions;
float takeHomePay;
cout << "Enter Weekly Sales: $";
cin >> weeklySales;
}
Next we go onto the next rectangle, it says "grossPay = weeklySales * .07". OK its saying the variable named grossPay will be assigned a value of weeklySales mulitplied by .07. First it looks at the variable weeklySales and looks what value it has then it does the multiplication then assigns grossPay with that resulting value. The next five rectangles are pretty much the same idea. Your code should now look something like this:
#include <iostream>
using namespace std;
void main()
{
float weeklySales;
float grossPay;
float fedTax;
float socSecurity;
float retirement;
float totDeductions;
float takeHomePay;
cout << "Enter Weekly Sales: $";
cin >> weeklySales;
grossPay = weeklySales * 0.07;
fedTax = grossPay * 0.18;
socSecurity = grossPay * 0.06;
retirement = grossPay * 0.1;
totDeductions = fedTax + socSecurity + retirement;
takeHomePay = grossPay - totDeductions;
}
OK now that all of our variables have values lets move onto the last rhombus what-chu-ma-call-it. It says....you can read scroll up. Basically it wants to output all the information we have onto the console so that the user can see it and along with a description for each piece of information, each on its own line, NOT A FREAKING PROBLEM. Again we are going to use the cout in combination with the information we have in our variables, but before all that we have to cout a special line:
cout << fixed << setprecision(2);
This one line is used to specify how many digits to show after the decimal point and because cent in currency takes up 2 digits as in 00 to 99 we specify 2 as a parameter. You will also need to include a new #include line at the top to be able to use this:
#include <iomanip>
Now we can go a head and cout our information.
this is how each line should look like:
Cout << "Description Here" << variableHere;
So in your code should look something like this:
Alternatively it can also look like this:#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
float weeklySales;
float grossPay;
float fedTax;
float socSecurity;
float retirement;
float totDeductions;
float takeHomePay;
cout << "Enter Weekly Sales: $";
cin >> weeklySales;
grossPay = weeklySales * 0.07;
fedTax = grossPay * 0.18;
socSecurity = grossPay * 0.06;
retirement = grossPay * 0.1;
totDeductions = fedTax + socSecurity + retirement;
takeHomePay = grossPay - totDeductions;
cout << fixed << setprecision(2);
cout << "\nTotal Sales:\t\t $" << weeklySales;
cout << "\nGross pay (7%):\t\t $" << grossPay;
cout << "\n\nFederal tax paid:\t $" << fedTax;
cout << "\nSocial security paid:\t $" << socSecurity;
cout << "\nRetirement contribution: $" << retirement;
cout << "\nTotal deductions:\t $" << totDeductions;
cout << "\n\nTake home pay:\t\t $" << takeHomePay << endl;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float weeklySales,
grossPay,
fedTax,
socSecurity,
retirement,
totDeductions,
takeHomePay;
cout << "Enter Weekly Sales:\t $";
cin >> weeklySales;
grossPay = weeklySales * 0.07;
fedTax = grossPay * 0.18;
socSecurity = grossPay * 0.06;
retirement = grossPay * 0.1;
totDeductions = fedTax + socSecurity + retirement;
takeHomePay = grossPay - totDeductions;
cout << fixed << setprecision(2)
<< "\nTotal Sales:\t\t $" << weeklySales
<< "\nGross pay (7%):\t\t $" << grossPay
<< "\n\nFederal tax paid:\t $" << fedTax
<< "\nSocial security paid:\t $" << socSecurity
<< "\nRetirement contribution: $" << retirement
<< "\nTotal deductions:\t $" << totDeductions
<< "\n\nTake home pay:\t\t $" << takeHomePay << endl;
}
The reason why I only have an endl at the very end is because at the beginning of every description I have a \n and that means a new line, some have 2 \n and that is because there is double spacing (refer to the sample to see were double spacing comes in). You will also notice the \t, it represents a horizontal tab. If you already know what it is skip this, if not read on. If you were to imagine the console being split up into pieces the beginning of each piece is a tab. Anything to the right of \t will be started at the next tab, or if you put \t\t it will be the 2 tabs away or if \t\t\t it will be 3 tabs away. Here is an image that might help:
Finally we add a system("pause"); so that we can see the output. Your code should look something like this when completed:
In the console input 28000 and press enter, Alt + Print-screen and paste it into a new word document along with the source code.#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
float weeklySales;
float grossPay;
float fedTax;
float socSecurity;
float retirement;
float totDeductions;
float takeHomePay;
cout << "Enter Weekly Sales: $";
cin >> weeklySales;
grossPay = weeklySales * 0.07;
fedTax = grossPay * 0.18;
socSecurity = grossPay * 0.06;
retirement = grossPay * 0.1;
totDeductions = fedTax + socSecurity + retirement;
takeHomePay = grossPay - totDeductions;
cout << fixed << setprecision(2);
cout << "\nTotal Sales:\t\t $" << weeklySales;
cout << "\nGross pay (7%):\t\t $" << grossPay;
cout << "\n\nFederal tax paid:\t $" << fedTax;
cout << "\nSocial security paid:\t $" << socSecurity;
cout << "\nRetirement contribution: $" << retirement;
cout << "\nTotal deductions:\t $" << totDeductions;
cout << "\n\nTake home pay:\t\t $" << takeHomePay << endl;
system("pause");
}
Gather the project folders for A,B and C and also the 3 word documents and zip them altogether for submission.
Week1 DONE!!!



