Professional Documents
Culture Documents
Lab 1
Lab 1
Lab No. ( 1 )
Introduction
4. After downloading the file, double click on it to start the installation process.
1
5. Click OK.
6. Click Ok.
7. Click I Agree.
2
8. Click Next.
9. Click Install.
3
10. Click Finish.
4
12. You can start a new empty source file by clicking New followed by Source file.
5
13. You now have a new empty source file.
6
14. You can write the following program in the source file:
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
double avg;
cout << "Input three integers:" << endl;
cin >> a >> b >> c;
avg=(a+b+c)/3.0;
cout << "Average=" << avg << endl;
system("pause");
return 0;
}
15. You can now run the program by clicking Execute followed by Compile & Run or click on :
7
16. You will be asked to save the file. Choose a suitable name.
17. If the file is already there and you want to overwrite it, click Yes.
8
18. The output.
9
4. The following screenshoot is displayed.After setup is completed loading of installation
components, click on Next button.
5. The following screenshoot is displayed. Mark the indicating that you have read and accepted
the license terms, Then Next button is activated, click on Next button to continue Microsoft
Visual Studio 2010 Ultimate installation.
11
6. The following screenshoot is displayed.Select features to install:
a. Full:complete Visual Studio installaion.Install all programming languages and tools.
b. Custom:select which programming languages and tools to install on the next page.
7. The following screenshoot is displayed showing the progress of installing VS2010 component
11
After installing Microsoft .NET Framework 4.0 Beta 2 you must restart your computer to complete the
installation.
Microsoft Visual Studio 2010 installation will automatically continue after your computer is started.
And after some time, it completes the VS2010 installation.
8. After all components listed on the above screen are installed the below result screen is displayed
to show the successful completeness of Visual Studio 2010 Ultimate setup.
12
9. The first time you start Visual Studio, you will see the following screen:
10. Creating “Hello World” C++ Program in Windows Using Microsoft Visual Studio 2010
1) Start Microsoft Visual Studio 2010 Ultimate from Start All Programs Microsoft Visual
Studio 2010 Microsoft Visual Studio 2010 as shown in the following screenshot:
13
3) Choose the type the project such as General and the Empty Project template and put the name of the
project. For example, we type my first project for our C++ project. Moreover, you may put
the Location text box, to save the project to the desired space of your computer hard disk and finally
click on OK button.
14
4) Solution Explorer will be appeared on Microsoft Visual Studio. From Solution Explorer, just right-
click on Source Files folder and choose Add and then click Add New Item.
5) You now have to add your program. Click on C++ File (.cpp) under Templates and write the name
of the program in the Name text box. For example, we type my first file for our program. At last,
click Add button to complete the creation of .cpp file.
15
6) Now, we have to type the code of our Hello World program. Just type the following lines of code.
#include<iostream>
int main()
{
cout << "Hello World !!!";
system(“pause”);
return 0;
}
7) Compile the program by clicking on Build menu, and then compile. If everything is ok a successful
message will appear to show that your program is build successfully. Otherwise, you will get error
message. Then you need to correct the codes.
16
8) Run your program by clicking the start debugging from the Build menu then the output will appear
on a Command Prompt window.
17
18
PART 2: Introduction to C++ programming:
Examples
#include<iostream>
using namespace std;
int main()
{
int feet;
cout << "Enter an integer:";
cin >> feet;
cout << endl;
cout << feet <<" Feet = " << 12* feet << " Inches"<< endl;
system("PAUSE");
return 0;
}
The output:
Enter an integer:3
3 Feet = 36 Inches
Press any key to continue . . .
#include<iostream>
using namespace std;
int main()
{
int length;
int width;
cout << "Enter two integers:";
cin >> length >> width;
cout << endl;
cout << "Area = " << length*width << endl;
system("PAUSE");
return 0;
}
The output:
Enter two integers:4
5
Area = 20
Press any key to continue . . .`
19
3. An example of the data types sizes.
#include<iostream>
using namespace std;
int main()
{
cout << "the size of char is:" << sizeof(char) << endl;
cout << "the size of int is:" << sizeof(int) << endl;
cout << "the size float is:" << sizeof(float) << endl;
cout << "the size of double is:" << sizeof(double) << endl;
system("PAUSE");
return 0;
}
The output:
the size of char is:1
the size of int is:4
the size float is:4
the size of double is:8
Press any key to continue . . .
Exercises
21
Solve the following questions:
2. Write a C++ program to find y = b++ * c/b + --c%2 + ++a%c *b. a, b, c are entered by user.
3. Write a C++ program that computes a salary of a part time employee based on:
- Number of days worked.
- Number of hours per day assuming that he worked the same hours every day.
- The hourly wage.
Choose the suitable data type for each variable.
4. Write a program that reads radius and height of a cylinder and computes its volume and surface
area. The surface area is the surface of the 2 circular bases and the surface of the lateral side.
volume r 2 h surface area 2r r h 2 r 2
21