The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 327 Weeks Ago, 5 Days Ago |
| Questions Answered: | 12843 |
| Tutorials Posted: | 12834 |
MBA, Ph.D in Management
Harvard university
Feb-1997 - Aug-2003
Professor
Strayer University
Jan-2007 - Present
Student Lab Activity
CIS170C Week 1 Lab Instructions
Lab 1 of 7: Getting Started (Your First C++ Programs)
Lab Overview—Scenario/Summary
Welcome to programming with C++. The purpose of this three-part lab is to walk you through the following
tutorial to become familiar with the actions of compiling and executing a C++ program.
In general, this lab will instruct you on
1.
2.
3.
4. how to create a project;
how to enter and save a program;
how to compile and run a program;
how to, given a simple problem using input and output, code and test a program that meets the
specifications; and
5. how to debug a simple program of any syntax and logic errors.
Deliverables
Section
Part A
Part B Deliverable
Step 6: Program Listing and Output
Program Listing and Output Points
10
10 Part C
All Parts Program Listing and Output
Total 20
40 Lab Steps
Preparation:
If you are using the Citrix remote lab, follow the login instructions located in the lab (under General Resources
within Course Resources) in Course Home.
Part A: Getting Started
Step 1: Start the Application
1. From the File menu, choose New Project.
2. Choose Win32 Console Application.
3. Enter a name in the name field.
4. Click OK.
5. Click Next, and choose the following options.
6. Application Type: Console Application
7. Additional options: Check mark Empty project.
8. Click Finish. Your project is now created.
Step 2: How to Add a Source Code File to Your Project (.cpp file) Page 1 of 7
CIS170C Week 1 Lab Instructions 1. In the Solution Explorer, right-click on the Source Files folder and select Add and then New Item.
2. In the next dialog box, choose C++ file (.cpp), enter a name for your source code file, and press the Add
button.
3. 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). Step 3: Create a Source Code File
Now enter the following C++ program exactly as you see it. Use the tab where appropriate. [Note: C++ is case
sensitive.] Instead of John Doe, type your name.
// --------------------------------------------------------------// Programming Assignment:
LAB1A
// Developer:
______________________
// Date Written:
______________________
// Purpose:
Ticket Calculation Program
// --------------------------------------------------------------#include <iostream>
using namespace std;
void main()
{
cout << "John Doe ticket program\n";
int childTkts, adultTkts, totalTkts;
cout << "Please enter the number of child tickets:";
cin >> childTkts;
cout << "Please enter the number of adult tickets:";
cin >> adultTkts;
totalTkts = childTkts + adultTkts;
cout << "The total tickets are: "<<totalTkts << endl; }
When you execute a program in debug mode (F5), the console screen may appear and disappear
before you have an opportunity to view your output. There are several techniques you can use to
pause the console screen so you can read the output. On the very last line in the main() function,
a. insert the statement: system("pause");
-ORb. insert an input statement: cin >> myVarable;
Step 4: Output
The black screen or console should read Page 2 of 7
CIS170C Week 1 Lab Instructions Step 5: Save Program
Save your program by clicking File on the menu bar and then clicking Save Program.cpp, or by clicking the Save
button on the toolbar, or Ctrl + S.
Step 6: Build Solution
To compile the program, click Build on the menu bar, and then click the Build Solution or Build LabA option. You
should receive no error messages. If you see some error messages, check the code above to make sure you
didn't key in something wrong. Once you make your corrections to the code, go ahead and click Build >> Build
Solution again.
Step 7: Execute the Program
Once you have no syntax errors, to execute or run your program, click Debug on the menu bar, and then click
Start Without Debugging.
Step 8: Capture the Output
Print a picture of your screen output. (Do a print screen, and paste this into MS Word.)
Step 9: Print the Source Code
Copy your source code and paste it into the same Word document as your screen print. Save the Word
Document as Lab01_LastName_FirstInitial.
Note: Using the Visual Studio editor to compile your programs creates a lot of overhead. These additional files will
become important as you create more sophisticated C# projects. Projects can contain one or more source-code
files. For this course, you will not have to worry about all the extra files that are created.
End of Part A
Part B: Debugging a program
Step 1: Create New Project
Now create a new project and name it LAB1B. Make sure you close your previous program by clicking File >>
Close Solution.
Step 2: Type in Program
Like before, enter the following program. Type in your name for Developer and current date for Date Written.
This program has three errors.
// --------------------------------------------------------------// Programming Assignment:
LAB1B
// Developer:
______________________
// Date Written:
______________________
// Purpose:
Average Program
// --------------------------------------------------------------#include <iostream>
using namespace std; Page 3 of 7
CIS170C Week 1 Lab Instructions void main()
{
cout << "Find the Average Program\n";
double num1, num2, num3, average;
cout << "Please enter number 1: ";
cin >> num1;
cout << "Please enter number 2: "
cin << num2;
cout << "Please enter number 3: ";
cin >> num3;
average = num1 + num2 + num3 / 3;
cout << "The average is: " << average << endl;
system("pause"); }
When you build the solution you will see the debugger. Double click on an error to locate the error. If it is a syntax
error, the error will be listed in the error list. Some errors will be underlined in red. Once you fix the syntax errors,
use the F11 (step into code) and F10 (step over code) commands to locate the logic error in the code.
Step 3: Save Program
Save your program by clicking File on the menu bar and then clicking Save Program.cpp, or by clicking the Save
button on the toolbar, or Ctrl + S.
Step 4: Build Solution
To compile the program, click Build on the menu bar, and then click the Build Solution or Build LabB option. You
should receive no error messages. If you see some error messages, check the code above to make sure you
didn't key in something wrong. Once you make your corrections to the code, go ahead and click Build >> Build
Solution again.
Step 5: Execute the Program
Once you have no syntax errors, to execute or run your program, click Debug on the menu bar, and then click
Start Without Debugging.
Step 6: Capture the Output
1. Capture a screen print of your output. (Do a PRINT SCREEN and paste into the Word document from
Part A.)
2. Copy your code and paste it into the same MS Word document that contains the screen print of your
output.
3. List all three errors.
4. Save this in the same Word document as Part JA.
End of Part B
Part C: Payroll Program
Step 1: Create a New Project
Create a new project and name it LAB1C. Make sure you close your previous program by clicking File >> Close
Solution.
Include a comment box like what you coded in Part B. This can go at the very top of your program.
Step 2: Processing Logic Page 4 of 7
CIS170C Week 1 Lab Instructions 22
Sample Output from Lab 1: Flowchart: (continued on next page) Page 5 of 7
CIS170C Week 1 Lab Instructions Pseudo Code:
1.
2.
3.
4.
5.
6.
7.
8. Declare variables
Accept Input – child tickets and adult tickets
Calculate Child ticket total = child tickets* 6
Calculate adult ticket total = adult tickets * 10
Calculate gross profit = child ticket total + adult ticket total
Calculate net profit = gross profit *0.2
Calculate distributor amount = gross profit – net profit
Display the following on separate lines and format variables with $ and decimal.
a. Gross Profit
value of gross profit
b. Net Profit
value of net profit
c. Distributor Amount
value of distributor amount Page 6 of 7
CIS170C Week 1 Lab Instructions //include the iomanip header file at the top of the file
#include <iomanip>
//use fixed and setprecision(2) to format the number
//use setw(8) to control the width of the field
//use \t to control the spacing between fields
cout << fixed << setprecision(2);
cout << "Gross Profit :\t $" << setw(8) << grossProfit << endl;
Step 3: Save Program
Save your program by clicking File on the menu bar and then clicking Save Program.cpp, or by clicking the Save
button on the toolbar, or Ctrl + S.
Step 4: Build Solution
To compile the program, click Build on the menu bar and then click the Build Solution, or Build LabC option. You
should receive no error messages. If you see some error messages, check the code above to make sure you
didn't key in something wrong. Once you make your corrections to the code, go ahead and click Build >> Build
Solution again.
Step 5: Execute the Program
Once you have no syntax errors, to execute or run your program, click Debug on the menu bar, and then click
Start Without Debugging.
Step 6: Capture the Output
1. Capture a screen print of your output. (Do a PRINT SCREEN and paste into an MS Word document.)
2. Copy your code and paste it into the same MS Word document that contains the screen print of your
output.
3. Use the same Word document as Part A and B.
End of Part C
END OF LAB Page 7 of 7
CIS170C Week 1 Lab Instructions
Â
Attachments:
-----------