COMP122 Lab 1 – Source Code in Visual C++ and answers in word doc – Instant Delivery – Perfect Solution
COMP 122
Week 1 iLab – Part 1
Follow the instructions in COMP 122_W1_iLab_Part1_instructions.docx.
COMP 122
Week 1 iLab – Part 2
Complete the following two programs:
Programming Problem 1
John wants to know the values of the area and perimeter of a rectangle. John can take measurements of the length and width of the rectangle in inches. John’s measurements are expected to be accurate to within 0.1 inch.
1. Identify the inputs and outputs of the problem.
2. Identify the processing needed to convert the inputs to the outputs.
3. Design an algorithm in pseudo code to solve the problem. Make sure to include steps to get each input and to report each output.
5. Write the program to implement your algorithm. Test your program using your test cases. Did your program produce the values predicted in your test cases? Explain.
4. Identify two test cases, one using whole number values, and one using decimal number values. For each of the two test cases show what inputs you will use and what your expected outputs should be.
Part 1 Instructions:
COMP122: Week 1 iLab – Part 1
Introduction to Visual C++.NET (2010) IDE
Objectives
After completing this assignment, you should:
• be able to create an empty console-mode project in VC++.NET;
• know how to enter, compile, build, and run a C++ console-mode program;
• know some basic components of a C++ program, such as #include
• be able to use cin and cout. for simple text and numeric input and output;
• be able to use basic integer arithmetic operations, including modulus;
• know that integer division truncates;
• understand how the compiler reacts to several common syntax errors;
• understand the process of developing a test plan, including predicted output for specific inputs (test cases);
• know how a program reacts to division by zero;
• know where the .exe file is stored after a successful build; and
• know how to keep the Command Prompt window open at the end of a console-mode program.
C++ Console-Mode Program Development Procedure
Visual C++ is an IDE (Integrated Development Environment) for writing programs in C++. The object of this laboratory is to introduce you to the basic features of an IDE (source-code entry and editing, compiling, linking, and execution) and some basic C++ programming statements to do some mathematical operations and simple input/output.
WARNING: Accurate typing is the key to success here. Although the compiler is tolerant of extra “white space” (spaces, tabs, and blank lines), it is very fussy about other syntax (punctuation, keywords, variable names, upper and lower case requirements, etc.), so be sure to type in the program below exactly as written, including case.
In addition to showing how to create and run a program in VC++.NET, this exercise discusses how to test a program, which involves selecting test inputs and predicting what output the program should generate, then observing the actual output, comparing the two, and analyzing any differences.
Open Visual C++ .NET
Open Microsoft Visual C++ 2010.NET by double-clicking on its icon.
Figure 1: When you open Visual C++ .NET, it should look similar to this image.
You may find it convenient to maximize this screen if it is not already maximized.
To set up your project, either select File -> New -> Project from the menu, or click on New Project in the upper-left part of the window. In the New Project window that is displayed, select Visual C++ – Win32 as the template on the left-hand side of this window. On the right-hand side of this window, select Win32 Console Application. (NOTE: There are different project types, so be sure to select the correct one, Win32 Console Application). On the Name line, enter the name of this project, e.g. Lab01. In the Location line, enter the directory where you want your project to be stored. Your screen should look like the following:
NOTE: If the Start Page (Figure 1) does not appear, click the Help menu and select Show Start Page.
Figure 2: New Project Window
Click OK. If you see a pop-up window indicating that your project location cannot be fully trusted, click OK. Next, the Win32 Application Wizard window appears. It looks like the following:
Figure 3: Initial Win32 Application Wizard Window
Click the Application Settings on the left-hand side of the Win32 Application Wizard window. The Application type should already be Console application (select it if not), then, under Additional options, select Empty project. The window should look like Figure 4.
Figure 4: Applications Settings Window of the Win32 Application Wizard
Click Finish to complete the creation of this project. The IDE should appear similar to the display below.
Adding a Source Code File to Your Project
First, click on the Solution Explorer on the left side of the window. The Solution Explorer window should expand to show your project directory and the folders that it contains. There are folders for various types of files that are often part of C++ projects. Your display should look similar to the following screenshot.
The easiest way to add a file to the project is to right-click on the project name (Lab01) in the Solution Explorer window. This pops up a menu from which you should select Add -> New Item. You can also right-click on the Source Files folder, which also pops up a menu from which you can select Add -> New Item. The following window should appear.
Select Code from the Installed Templates pane on the left, then select C++ File (.cpp) from the pane on the right. Finally, fill in the name for the new file that you are adding to your project. Your display should look like the following screenshot. Then, click Add.
After adding the file to your project, notice that your source file edit window now appears as the main pane of the window. It has the name of your source file on the tab at the top of the pane as is shown below. You use this window to edit your code.
Enter Source Code Using the Text Editor
Use the built-in text editor to enter the source code for your first program. The C++ source code is shown below. The text editor in Visual C++ works similarly to a word processor in many ways: You can cut and paste, backspace, select, and move text, etc. It also has some special features that are useful for entering C++ programs. For example, it displays keywords, such as int, main, #include, if, while, etc., in a different color, and it automatically indents blocks of code for readability.
Type in the program below exactly as it appears, except in the prologue (explanatory text at the beginning of the program) put your initials in place of XXX in the file name, and put your name and the current date, as shown.
Spacing is not always critical in C++ (sometimes it is, sometimes it is not), but punctuation and upper-/lower-case letters are. Note especially the use of the semi-colon at the end of most lines in the program, and the use of braces, { }, at the beginning and end of the program (after the line with main). The various statements are discussed in the text.
C++ Source Code
Once you have entered text in your edit window, you can save your project from the File menu by selecting File -> Save All. Once you have saved your project, select the Solution Explorer on the left side of your window. You should see your source-code file under the Source Files folder of your project as shown below.
Compile and Link = Build
The next step is to compile and link the program. This two-step process is called building your project. Compiling a program translates your text-file source code to machine-executable code that can be run on the host computer (in this case, a PC running Windows®), and linking connects your program to system code and objects that your program uses. The program in this laboratory uses system objects, cin and cout, so the linking step connects your program to them to produce the final executable file. To compile and link your source code, choose Build Solution from the Debug menu, or press F7.
Figure 9: After you have entered the program, click the Debug-Build Solution menu item (F7) to compile and link it.
A pop-up window asks if you want to re-build the project. Click Yes. You may get one more pop-up window asking if you want to overwrite the existing project. Click Yes if you get this window. If everything is OK, you will get 0 compile errors and 0 warnings.
Figure 10: A good build will have 0 compile errors and 0 warnings.
Compiler Errors and Warnings: Debugging
If the code has any syntax errors, you will get compiler errors. If there are any compiler errors, it cannot create an executable file. You must fix all compiler errors before you can execute the program. Error messages appear in the bottom panel of the Visual C++ window. If you cannot see them, use the scrollbar on the right side of the panel. If you double-click an error message, a little arrow will appear in the left margin of the text editor window to indicate the line that may have the error. Compilers are notorious for having misleading error messages and not flagging the correct line, but they at least give you a clue about where the problem is located. If you get compiler errors, try to troubleshoot them yourself. Look closely at the line flagged by the compiler and at the line above it (which is often where the error actually is located). Most errors are caused by incorrect typing, misspelling something, incorrect punctuation, or incorrect case.
Oftentimes, a single error in one line will precipitate compiler errors in following lines, even though they are correct. Therefore, the best approach, if you have multiple compiler errors, is to fix the first one and recompile (Build). Often, fixing the first problem also fixes several other errors.
Some lines of code will cause the compiler to issue a Warning instead of an error. If there are only warnings and no errors, the compiler will usually be able to create an executable file. Depending on the problem, your code may still work fine, but, in general, you should fix all warnings so that you get a completely clean build.
If you get any compiler errors or warnings, try to fix them, but if you cannot figure out what to do, ask your instructor or F.A. for assistance. Remember, C++ is quite fussy about most details (punctuation, spelling, case, etc.), so edit your code carefully.
If the code compiles correctly, the next step that Visual C++ .NET performs is linking. This step simply connects your program with prewritten programs and objects that you use in your program (cin and cout in this example).
Background: Testing and Types of Errors
Just because your code compiles without errors, does not mean that it will execute correctly!
It is still possible that a program contains run-time errors.
Run-time errors fall into two basic categories: system errors and logical errors.
System Errors
System errors occur when your program runs and tries to do something that the host computer cannot or will not do, for example, divide by zero. The good news about system errors is that the system detects them, stops your program, and gives you an error message.
Logical Errors
Logical errors are ones that do not produce compiler or system errors, but nonetheless produce wrong output. Since these errors do not produce any kind of warning or error message, they are particularly onerous. They include trivial errors, such as misspelled words in the program output, and more serious ones, such as incorrect calculated values.
The only way to test for logical errors is to predetermine the output for selected input values.
Each set of input values and predicted output is called a test case. Note the word predetermine. Before you try to run your program, you should predict the output for selected input values, in other words, you should determine the expected results for some set of inputs. Unless you know precisely what the output should be for some input values, how will you know if your program works correctly?
The objective of testing is not only to verify that a program works correctly, but also to discover if there are any ways that it does not work correctly. Testing, when done correctly, is almost as much work as writing the program.
While 100% testing of programs is usually not practical, you should always test your programs with a reasonably complete set of inputs. As you progress through your programming courses, you will learn more about selecting good test cases to test software reasonably thoroughly.
In general:
• Be meticulous when testing;
• Do not assume that things work properly; and
• Verify operations even if you think that they will work correctly. (You will be surprised by how often the result is not what you expect)!
Applying these principles to this laboratory, it is a good idea to test your program with a set of numbers, where number1 is greater than number2, and another set, where number1 is less than number2. Why? To verify that the division works correctly when the quotient should be greater than 1, and less than 1.
Since the data type of the variables number1 and number2 is int, they are signed numbers and you should include test cases with all possible combinations of signs: both numbers positive, both numbers negative, number1 positive and number2 negative, and number1 negative and number2 positive.
Other test cases should be selected so that the division is even (no remainder) and not even (the quotient has a fractional part, i.e., it is a floating point value). As you will discover, C++ has a few surprises: That is why it is important to be meticulous and reasonably thorough in your testing.
Finally, additional test cases should include testing for what happens when 0 is input for either number. The value of 0 definitely does cause problems when it is used as a divisor since divide by zero is illegal!
Oftentimes, it is most convenient to organize a test plan by putting the test cases in a table. Include columns for input values, predicted outputs, and observed outputs. This format is very concise and readable, and makes the comparison of predicted and actual outputs very easy.
Running the Executable File: Testing and Actual Results
With the test plan in hand and having compiled your code without any compiler errors or warnings, you are now ready to actually run your program and see if it works! One objective in this part of the exercise is for you to observe the program’s actual output, and compare the actual output to what you predicted and explain any differences.
From the Debug menu, select Start Debugging to execute this program. The IDE will present a DOS window, which provides prompts that you should respond to with the inputs to your test cases.
Submit Your Work
Run your code and execute your test cases. Record your selected test cases in the Part1 document for this iLab, with the predicted and actual results. Take a screenshot of your program running one of your test cases correctly, and paste it at the end of the Part1 document. Submit this screenshot as your solution.
NOTE: To take a screenshot, simply click on the window that you want to capture, then press the Alt key and the Print Screen key at the same time. That captures the image of the current window.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.