Programming Lab 1
Programming Lab 1
Table of Contents
1.
Introduction
2.
Activity Time-boxing
3.
4.
Concept Map
4.1
4.2
4.3
3
3
3
5.
6.
7.
5.1
5.2
3
4
6.1
6.2
6.3
4
4
8
Tools
Setting-up Visual Studio 2008
Walk-through Task
Practice Tasks
10
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
10
10
10
10
10
11
11
11
11
Practice Task 1
Practice Task 2
Practice Task 3
Practice Task 4
Practice Task 5
Practice Task 6
Practice Task 7
Out comes
Testing
8.
11
9.
Evaluation Criteria
11
10.Further Readings
10.1
10.2
12
Books
Slides
12
12
12
P age |1
2. Activity Time-boxing
Task No.
8
5.1
6.2
6.3
7
Total Time
60 mins
20 mins
5 mins
15mins
70 mins
170 mins
P age |2
4. Concept Map
4.1 Printing characters which are not part of a Keyboard
There are different types of characters on the keyboard such as: alphabets, numbers, and special
symbols. These symbols can be printed on the output screen as per the requirement. However, there
are certain characters which are not available on the keyboard and thus cannot be printed directly from
a keyboard. For example, when we want to print new line, there is no key on the keyboard which can be
used directly to print a new line. Similarly, if you want to print vertical tab, you do not have a key on the
keyboard to print it. In these scenarios, the escape sequences will help you. For example using the
escape sequence, \n, will help you to print a new line. Similarly, using the escape sequence, \v, will
help you to print a vertical tab etc. The details of further escape sequences can be found in Appendix A.
4.2 Printing special characters
There are certain characters which have special meanings in C++. For example double quotation marks
(), single quotation mark (), question marks (?)etc. For example, you know, the double quotation marks
() is used to print a text stream in the cout object. For example the following statement in C++:
cout<<Hello World;
However, these are certain times, when you need to print the quotation marks () itself in the text. To
achieve this task, you can use escape sequence, For example, the following statement in C++
cout<<\Hello\ World;
If you want to generate a sound from your program at a typical point, you can use escape sequence to
achieve this. For example, writing \a will make a bell alert in the program. The details of further
escape sequences can be found in Appendix A.
Solve the question number 1 and question 2 on the page number 109 of your text book. You need to
bring this code with you and need to give this code to the lab instructor.This code will be evaluated
and it carries certain marks as can be seen from the section 9, Table 2.You can use escape sequences
represented in Appendix A for formatting purposes.
Department of Computer Science,
MAJU, 2014
P age |3
Q1. Write a C++ program which would print the following screen as output:
*
******************************
Welcome to my program *
******************************
Q2: Write a C++ program which would print the following screen as output:
*** My Introduction ***
*Name: Your Name *
*DOB: Your Birthdate
*
*City: Your city
*
*Prog: Your Prog *
*The End*
6. Procedure& Tools
6.1 Tools
1) Go to start menu.
2) Click on Microsoft Visual Studio Folder.
3) Now select Microsoft Visual Studio as shown in the Figure 1.
1) Go to File menu.
2) Select New, a sub-window will open as shown in the Figure 2.
3) Select Project from the sub-window.
P age |4
6.2.3
1) Click on Project.
2) When you click on Project, a dialog box will open. On the dialog box, there are various options
like Windows Application, Console Application, DLLetc as shown in the Figure 3 (a).
3) From Application Type, Select Console Application as Figure 3 (b).
4) From additional options, select empty project as shown in the Figure 3 (b).
P age |5
After the step 6.2.3, you will see a screen just like shown in the Figure 4.
There would be different options like Add, Cut, Copy etc. Click on Add and a submenu will open.
6.2.5
Various options would appear. Click on add New Item to select a working file as show in the Figure 5.
P age |6
From the various options, click on C++ File (.cpp) as shown in the Figure 6.
.
Figure 6: Select CPP file
Write the name of your file in the Name field as shown in the Figure 7.
P age |7
When you click the Add button,A new file would be added to your existing project as shown in the
Figure7.
6.3 Walk-through Task
After completing 6.2task, now you are ready for the specialized task. You need to practice the following
task to get basic understanding of developing a small program using escape sequences. When you finish
this task, the following output will be printed.
*
*
**********
Hello
*
World *
Remember you created a file with name myprog in the task 6.2.7.now write the following code as
shown in the Figure 8. Write the code in the intended form as shown.
P age |8
6.3.2 Compilation
After writing the code, now you are ready to compile it. For compilation, select Build Solution from the
Build option in the menu bar as shown in the Figure 9.
When you click on build solution, the compiler would start processing your program. The progress of
build activity would be displayed on the output window as shown in the Figure 10.
The progress would show whether the build was successful or not. It would display the errors if any.
Otherwise it would display the message Build succeeded
.
6.3.3 Executing the Program
Now run the program by pressing Ctrl+F5 from keyboard or selecting play option from Debug menu
(Debug menu can be accessed from the Figure 10).When you press Ctrl+F5, the compiler would start
executing the program and would display the final output to your screen as shown in the Figure 11.
*
*
**********
Hello
*
World *
P age |9
7. Practice Tasks
This section will provide more practice exercises which you need to finish during the lab. You need to
finish the tasks in the required time. When you finish them, put these tasks in the folder specified by
your lab instructor.
7.1 Practice Task 1
***
*
*
*
*
*
Write a C++ program which would print the following screen as output:
Course Code |
CS1114
|
CS1234
|
CS1123
|
CS1121
|
CS1124
|
Total
|
Course Name
ITC
Computer Programming
Cal-I
Algebra
Discrete Maths
5
| Credit Hour
| 4
| 4
| 4
| 3
| 3
|18
Write a C++ program which would print the following screen as output:
Name
ENo
Dept
Rank
Sal
|
|
|
|
|
Zubair
1234
EE
Lecturer
12,000
Write a C++ program which would print the following screen as output:
Month | Num of Hours
Department of Computer Science,
MAJU, 2014
P a g e | 10
|
|
|
|
|
|
100
150
130
90
110
135
Write a C++ program which would print the following screen as output:
Allownces
House Rent
Medical
TA/DA
Bonus
|
|
|
|
|
Amount
1000
1500
2000
50000
Write a program in C++ using escape sequence which would produce the sound of a bell when user
enters the character.
7.8 Out comes
For this task, no test cases are required. The instructor will check the outputs of the practice tasks.
Table 2: Testing of Practice Tasks
Practice Tasks
T1
T2
T3
T4
T5
T6
T7
8. Evaluation Task(Unseen)
Confirmation
The lab instructor will give you unseen task depending upon the progress of the class.
9. Evaluation Criteria
The evaluation criteria for this lab will be based on the completion of the following tasks. Each task is
assigned the marks percentage which will be evaluated by the instructor in the lab whether the student
has finished the complete/partial task(s).
Department of Computer Science,
MAJU, 2014
P a g e | 11
Sr. No.
1
2
3
4
5
6
Task No
4.1
5
6 and 7
8
The slides and reading material can be accessed from the folder of the class instructor available at
\\dataserver\jinnah$\
Bell (alert)
Backspace
Formfeed
New line
Carriage return
Horizontal tab
Vertical tab
Single quotation mark
Double quotation mark
Backslash
Literal question mark
ASCII character in octal notation
ASCII character in hexadecimal notation
Unicode character in hexadecimal notation if this escape sequence
is used in a wide-character constant or a Unicode string literal.
For example, WCHAR f = L'\x4e00' or WCHAR b[] = L"The Chinese
character for one is \x4e00".
P a g e | 12