0% found this document useful (0 votes)
13 views5 pages

Handout No. 1

The document provides a guide on setting up the DEV-C++ environment and using escape sequences in C++. It includes instructions for downloading, installing, and creating a simple C++ project that outputs 'Hello World' and explains various escape sequences for formatting text. Additionally, it outlines tasks for practicing text output and drawing shapes using C++ code.

Uploaded by

erumbegum081
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Handout No. 1

The document provides a guide on setting up the DEV-C++ environment and using escape sequences in C++. It includes instructions for downloading, installing, and creating a simple C++ project that outputs 'Hello World' and explains various escape sequences for formatting text. Additionally, it outlines tasks for practicing text output and drawing shapes using C++ code.

Uploaded by

erumbegum081
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Objective:

Understand the basics of the DEV-C++ environment and set up a development workspace and
learn how to use escape sequences for formatting text output in C++.
DEV-C++ Compiler:
First of all, we will discuss how to download, install, and work on Dev-C++ compiler:
Installation:
double clock on the downloaded file and install it on computer and follow the instruction.
Working on DEV-C++:
After installation you will see a shortcut named Dev-C++ on your computer. Double click on the
shortcut you will have following screen.

Click on File > New > Project

Click on Console Application and Write project name as Hello and press OK Button.
Now click on Desktop icon to go to desktop. After that click on Create New Folder icon and write
folder name as Hello.

Double Click on folder named Hello that you just made. Write project name as Hello.dev and save
project inside the folder Hello by pressing Save Button.

Add following code in main.cpp file


Program: main.cpp
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
cout <<"Hello World"<<endl;
system("PAUSE");
return 0;
}
Save the file into Hello folder with name main.cpp by pressing Ctrl + S buttons from keyboard.
Now compile and run the code using Execute > Compile & Run menu. You can also press F11 key
to do the same. After successful compilation the program will run and it will show following output
on screen.

Escape Sequence:
In C++ programming, we can use some of the special characters with different behavior. These are
called escape sequence. The name reflects the fact that the backslash causes an “escape” from the
normal way characters are interpreted. In this case the \t is interpreted not as the character 't' but as
the tab character. A tab causes printing to continue at the next tab stop.
cout << "\"Run, \tForrest, run,\" she said.";
This translates to "Run, Forrest, run," she said.
The following table shows escape sequence characters with their ASCII values
Escape ASCII
Character Purpose
Sequence Value
\0 000 Null Null character. Marks the end of string
\a 007 Bell A beep sound is generated
\b 008 Back Space To erases one character from left side of cursor
position
\t 009 Horizontal Tab To shift cursor couple of spaces to the right
\n 010 New Line To shift the cursor to the new line
\r 013 Carriage Return To move cursor to the beginning of current line
\" 034 Quotation Mark ( " ) To display double-quote character
\' 039 Apostrophe ( ' ) To display single-quote character
\? 063 Question Mark ( ? ) To display question mark character
\\ 092 Backslash ( \ ) To display backslash character
Table: Escape Sequence Characters
When the backslash character appears within quotes it is called the escape character. If another
character follows it immediately without a space, it is called an escape sequence. The table above shows
some of the escape sequences and the results that they produce.
cout << "This is my first program in C++\n";
As a result of the statement above, the string This is my first program in C++ will be displayed on
the screen and the cursor will move down to the beginning of the next line. The movement of the cursor
to the next line is dictated by the escape sequence \n. It has the same effect as cout << "This is my
first program in C++" << endl;
OR
cout << "This is my first program in C++";
cout << endl;
Similarly, to move the cursor a certain number of spaces forward, without actually printing anything on
the screen, we use the tab or \t escape sequence. Notice how the output will change if we write:
cout << "This\t is\t my\t first\t program\t in\t C++\n";
Similarly,
• \r takes the cursor to the beginning of the current line.
• \b is for backspace which will take you one space backwards. If \b is used immediately after \t,
it has the effect of moving one whole tab backwards – just like in WinWord.
In addition to this, if you want to take input from the user in the first task. You wil use following code.
int variablename;
cout << "Enter a number: ";
cin >> variablename;

Where ‘variablename’ is the name of an integer variable which has been defined earlier. These three
statements will allow the user to enter any signed integer which will be stored in ‘variablename’.
Similarly,

char grade = 'B'; // the value assigned to a character is always


written
// inside single quotes. assigned using ' '.
cout << "Enter course grade: ";
cin >> grade;

Note: a variable of type char can only store one character at a time. Therefore, in the above case
writing grade = 'B+'; would have be illegal.
Task 1: Write your name and college name on screen.
Here is the sample Output
My Name is ( Your Name ) and I did F.Sc. from ( College Name and City Name).
Write programs that display the output shown in the following diagrams.
Task 2:
Make a boat shape on screen

--
/||
/ ||
/ ||
/ ||
----||
||
____________||________
\ /
\ /
\________________/
Press any key to continue . . .

Task 3:
Show Following output on screen. Write your name inside a Box. Read ASCII Table to see characters
needed to draw a double lined box.

╔═══════════╗
║ Your Name ║
╚═══════════╝
Press any key to continue . . .

You might also like