Lecture Lab-1
Lecture Lab-1
Practical 1
Revision of (Object Oriented) Programming In C++
Objectives
The main purpose of this Lab Practical is to introduce students with basic concepts of C++. The components
of programs, such as key words, variables, operators, and punctuation are covered. Basic parts of a C++
program, data types, the use of variables and literals, assignment statements, simple arithmetic operations,
program output, and comments.
Scope
The Scope of this lab practical is to:
Implement initialization and declarations of variables
Develop a simple program in MS Visual C++
Design Pseudocode for various programming problems
Solve numeric problems using arithmetic operations
Activity Time Boxing
Task Activity Name Total
No. Time
1 Concept Deliverance 30
2 Setting Up MS Visual C++ 10
5 Evaluation/Marking 60
Total Time: 180
int main() {
cout << "Hello, World!\n";
return 0;
}
Program Statements:
The program statement is the fundamental unit of C++ programming. There are two statements in the
FIRST program: the line
cout << "Hello, World!\n";
and the return statement
return 0; // A semicolon signals the end of the statement
The identifier cout (pronounced “C out”) is actually an object. It is predefined in C++ to correspond to
the standard output stream. The operator << is called the insertion or put to operator. It directs the
contents of the variable on its right to the object on its left.
Directives
The two lines that begin the FIRST program are directives.
They’re not part of the basic C++ language, but A C++ program can be divided into different
they’re necessary anyway namespaces. A namespace is a part of the
program in which certain names are recognized;
outside of the namespace they’re unknown.
It isn’t part of a function body and doesn’t end
with a semicolon
(#). It’s called a preprocessor directive. It is an
instruction to compiler to include another file in
the current program with name of iostream
header file
Start
Stop
Find for any logical errors e.g directives and libraries are not added
Identifiers in C++
An identifier is a programmer -defined name that represents some element of a program. Variable names
are examples of identifiers.
Legal Identifiers
Basic C++ Data Types
Escape Sequences
Escape sequences can be used as separate characters or embedded in string constants. Table 2.1 shows a
list of common escape sequences.
\n Newline
\t Tab
\a Bell /Beep
\b Backspace
\f Form feed
\r Return
\’ Single quotation mark
\” Double quotation marks
\\ Backslash
\xdd Hexadecimal notation
PRE-Lab
To create your app, first, you'll create a new project and solution.
1. If you've just started Visual Studio, you'll see the Visual Studio 2019 dialog box. Choose Create a
new project to get started.
2. Otherwise, on the menubar in Visual Studio, choose File > New > Project. The Create a new
project window opens.
3. In the list of project templates, choose Console App, then choose Next.
4. In the Configure your new project dialog box, select the Project name edit box, name your new
project Calculator Tutorial, and then choose Create.
5. An empty C++ Windows console application gets created. Console applications use a Windows
console window to display output and accept user input. In Visual Studio, an editor window opens
and shows the generated code:
6. To build your project, choose Build Solution from the Build menu. The Output window shows
the results of the build process.
In-Lab
Practice Tasks
Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5 units by
creating a class named 'Triangle' with the constructor having the three sides as its parameters?
Write a program to print the area of a rectangle by creating a class named 'Area' having two
functions. First function named as 'setDim' takes the length and breadth of the rectangle as
parameters and the second function named as 'getArea' returns the area of the rectangle. Length
and breadth of the rectangle (Take input from user)?
Evaluation Criteria:
As defined in Lab Rubrics.
Post-Lab
Task #1: