Chat with us, powered by LiveChat dvry comp122 week 1 iLab 1 of 7: Introduction to Visual C++ .NET | Writedemy

dvry comp122 week 1 iLab 1 of 7: Introduction to Visual C++ .NET

dvry comp122 week 1 iLab 1 of 7: Introduction to Visual C++ .NET

Question

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<iostream>;using namespace std;; int main( );return 0;; opening and closing braces, { and }; and theint data type;

· be able to usecin andcout. 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 exactlyas 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.

Figure1: 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 -> Projectfrom 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 Wizardwindow. 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 asint,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 appearsexcept 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 withmain). The various statements are discussed in the text.
C++ Source Code


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 andcout, 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.

The Debug – Build Solution (F7) compiles and links your program, producing an executable file if there are no syntax errors!

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. ClickYes. You may get one more pop-up window asking if you want to overwrite the existing project. ClickYes if you get this window. If everything is OK, you will get 0 compile errors and 0 warnings.

Results of the build (compile and link) are shown here.

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 andcout 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 wordpredetermineBefore 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, wherenumber1 is greater thannumber2, and another set, wherenumber1 is less thannumber2. 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 variablesnumber1 and number2 isint, they are signed numbers and you should include test cases with all possible combinations of signs: both numbers positive, both numbers negative,number1 positive andnumber2 negative, andnumber1 negative andnumber2 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.

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order