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.
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
- 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
- how to debug a simple program of any syntax and logic errors.
Deliverables
Section | Deliverable | Points |
Part A | Step 6: Program Listing and Output | 10 |
Part B | Program Listing and Output | 10 |
Part C | Program Listing and Output | 10 |
All Parts | Total | 30 |
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 | |
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. | |
Step 2: How to Add a Source Code File to Your Project (.cpp file) | |
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). | |
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”); -OR- b. insert an input statement: cin >> myVarable; | |
Step 4: Output | |
The black screen or console should read | |
Step 5: Save Program | |
Save your program by clicking Fileon 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; 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 | |
Capture a screen print of your output. (Do a PRINT SCREEN and paste into the Word document from Part A.)Copy your code and paste it into the same MS Word document that contains the screen print of your output.List all three errors.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 |
You need to write a program that calculates and displays the revenue earned from ticket sales at a movie theater. Input: Prompt the user for the number of adult tickets. Prompt the user for the number of child tickets. Process: Perform the calculations. The adult tickets cost $10.00 and the child tickets cost $6.00. The theater keeps 20% of the gross box office profit, and the rest goes to the movie distributor. Output: Display the results. Sample Output from Lab 1: Flowchart: (continued on next page) |
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 |
Capture a screen print of your output. (Do a PRINT SCREEN and paste into an MS Word document.)Copy your code and paste it into the same MS Word document that contains the screen print of your output.Use the same Word document as Part A and B. |
End of Part C |
END OF LAB |
We've got everything to become your favourite writing service
Money back guarantee
Your money is safe. Even if we fail to satisfy your expectations, you can always request a refund and get your money back.
Confidentiality
We don’t share your private information with anyone. What happens on our website stays on our website.
Our service is legit
We provide you with a sample paper on the topic you need, and this kind of academic assistance is perfectly legitimate.
Get a plagiarism-free paper
We check every paper with our plagiarism-detection software, so you get a unique paper written for your particular purposes.
We can help with urgent tasks
Need a paper tomorrow? We can write it even while you’re sleeping. Place an order now and get your paper in 8 hours.
Pay a fair price
Our prices depend on urgency. If you want a cheap essay, place your order in advance. Our prices start from $11 per page.