Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

+1 (22316)

Oiented Programming
Using C
Object

Daical No. 1: Develop minimum 2 programs using constants, variables,


arithmetic expression, operators, exhibiting data type conversion.

Practical Significance:
oI constants and variables facilitates the evaluation of
. The declaration
arithmetic expressions in real life problems.
The data type conversion helps in real life problems to get the accurate results
2.
arthmetic expressions.
of evaluation of

Relevant Program Outcomes (POs)


of basic mathematics, sciences and basic
1. Basic knowledge: Apply knowledge
to solve the broad-based Computer engineering problem.
2.
engineering
Discipline knowledge: Apply Computer engineering discipline - specific

knowledge to solve core computer engineering related problems.


to use the
3. Experiments and practice: Plan to perform experiments and practices
results to solve broad-based Computer engineering problems.
tools: relevan' Computer technologies and tools with an
Engineering Apply
understanding of the limitations.
5. Communication: Communicate effectively in oral and written form.

Practical skills
Competency and
is expected to develop the following skills in you
This practical
Develop C++ programs to solve broad-based problems
. Define and declare constants and variables.
2. Use data type conversion.
3. Compile the program.
4. Debug and execute the program.

IV Relevant Course Outcome(s)


Develop C++ programs to solve problems using Procedure Oriented Approach.

Practical Outcome (POOs)


Write/ Compile/ debug / Execute simple C++ program using constants,
variables, arithmetic expressions and data type conversion.

VI Relevant Affective domain related Outcome(s)


1. Select proper programming environment in C++
2. Follow ethical practices.

VII Minimum Theoretical Background


C++ Basic Input/Output:
C+O operation is using the stream concept. Stream is the sequence of bytes or flow of
data. It makes the performance fast. If bytes flow from main memory to device like
printer, display screen, or a network connection, etc, this is called as output operation. If
Dytes floW from device like printer, display screen, or a network connection, etc to main
memory, this is called as input operation.

Maharashtra state Board of


Technical Education
Object Oiented Propamming Using ° 11 (22316)

Function and Description


lHeader File
Iis used to deline
the cout, cin and cerr objccts,
slandard
iostrean standard
stream,
output
which corespond to
standard error stream, respcctively.
strcam and
Input

services useful for


I1 is used to declare sctprecision
and
<iomanip formatted I/0, such
as
performing
sctw. user-controlled
services for
It is used to declare
fstream
fileprocessing.

Standard output stream (cout)


of ostream class.
The cout is a predefined object which is usually
a display screen.
standard output device, the
connected with the 1o display
tis (<<)
is used in conjunction
with stream insertion operator
The cout

output on a console.
Standard input stream (cin)
istream class.
The cin is a predefined object of a keyboard.
is usually
It is connected with the standard input device, which to read the input
with stream extraction operator (>>)
The cin is used in conjunction
from a console.

Standard end line (endl)


class.
predefined object of
ostream
The endl is a
line characters and flushes the stream.
It is used to insert a new

execution of a program
change its value during
Constants: A variable which does not value of a constant will
constant variable. Any attempt to change the
Is known as a data types,
constant in C++ can be
of any of the basic
result in an error message.
A
shown below:
const qualifier can be
used to declare constant as

const float PI = 3.1415;


value 3.1415.
The above declaration means that PI is
a constant of float types having a
declarations are:
Examples of valid constant
const int RATE = 50;

const float Pl = 3.1415;

const char CH = 'A';

Literal constants: can be classified into: integer, floating-point, characters, strings,


literals.
Boolean, pointers, and user-defined

C++: true, false and nullptr: true and


Other literals: Three keyword literals exist in
false are the two possible values for variables of type bool. nullptr is the null pointer
value.
bool foo true;
bool bar =false;
int* p nullptr;

Maharashtra state Board of Technical Education


(2231s
Programmng USng C++
Obect Oriented

nitions (#definc): Another mechanism to name constant valucs is the


Preproccssor definit

use ofnreprocessor definitions. They have the following form


Syntax: #dcfine identifier replacement
Example #define PI 3.14159
#define NEWLINE "n'

Rasic Data Types:


C++ supports a large number of data types. The built in or basic data
sSDDorted by C++ are integer, floating point and character. C++ also provides
for variables that can hold only the values True and falsc. Somc
the data type bool
are summarized in table along with
commonly used data types
description.
Size in bytes
Type Description
Int Small integer number
4
longint Largeinteger number
4
float Smallreal number
double Double precision real number
long double Long double precision real number
char A Single Character

location in the computer memory which can store data and is


Variable: Variable is a

name for easy reference. The variables can be used


to hold different
given a symbolic
during the execution of a program.
values at different times

Declaration of a variable and Initialization:


Example: float total;
int x, y
int a 20;

Type Conversion: The process in which one pre-defined type of expression


is converted into another type is called conversion. There are two types of
conversion in C++.
1. Implicit conversion
2. Explicit conversion
Implicit conversion: Data type can be mixed in the expression. For
Example double a,
intb 5;
float c 8.5;
a =b* c,
When two operands of different type are encountered in the same

expression,
Explicit conversion: It is also called type casting. It temporarily changes a
variable data type from its declared data type to a new one.

Syntax: (type) expression;


Example: (f1loat) (x t y/2)

Maharashtra state Board of Technical


Education
Object Oriented ProgrammingUsing C++ (22316)
VIII Resources required
Sr. Name of Quantity Remarks
No Specification
Resource
1. Hardware Computer (i3-i5
preferable), RAM
Computer minimum 2 GB and
System onwards, HDD 40GB and
As per batch
above For all
size
2. Operating Windows /LINUX Experiments
system

3 Software Turbo C+ Version 3.0 or any


other

IX Precautions
. Handle computer system and peripherals with care.
2 Follow safety practices.

X Resources used
S. No Name of Resource Specificati
Computer System Tnlel core 3 Rom: 4r
with broad specifications
HO: 4T8.
Software Turbo C
Any other resource used

XI Result (Output of the Program)


Ente...Coeffic/ent. b, C
.......

oots are eal cutfene ni 0.2S,a2-i


XII Practical Related Questions
Note: Below given are few sample questions
for reference. Teacher must design
more such questions so as to ensure the achievement
of identified CO.
(Note: Use Point VIII to X and XIIl to XV for all relevant programming exerCise use
blank pages provided or attach more pages
if needed.)
1. Constantvaniables can be created in C - by usingboh a 2b
a. const b. #define d. Both a& b d. None of these

2. State output of the following code:

Ta

T. a= 1

Maharashtra state Board of Technical Education


Object Oriented Programming Usng
C+ (22316)

num c a tbt -b
Output
a
cout <K c;

7
7-S
3 Regarding following statement which of the statements is tnuc? const int
a) Declares a variable a with 100 as its initial value
a =
100;
b) Declares a construction a with 100 as its initial
value c) Declares a constant a whose value will be

100
d Constructs an integer type variable with a as identifier and 100 as value

4, Which of the following statement is not true about preprocessor directives?


a) These are lines read and processed by the
preprocessor b) They do not produce any code by
themselves
c) These must be written on their own
line d) They end with a semicolon

XIII Exercisee

Attempt Q1 or Q2 and Q.3 a orb from the following:


(Note: Use Point VIII to X and XIII to XV for all relevant programming exercise use
blank pages provided or attach more pages if needed.)

1.Write a C++ program to evaluate the following expressions:


X1
-b+b-4ac X1
X2
-=b-vb-4ac
2a 2a
2. Write a C++ program to demonstrate the of oprator
use
precedence.
3. Complete the given table:
Program Code
Write& justify Output
a #include<iostream.h>
#define PI
int main ()
3.14159
Ouput: 12.366 36
float r = 2;
float circle
Circle = 2 * PI* r;
Circle 2*, PT *6
Cout << circle;
return 0; 22 3.144 *2

12.SC636

Maharashtra state Board of


Technical Education
Object Oriented Programming Using C++ (22316)
a) #include<iostream.h> Output reJ 7 2s
#include<conio.h>
void main ()

clrscr ();
float res
HHere F 2 remans
float fl=15.5, f2=2
res (int)f1/ (int) f2; as 's is not
Outisres<<endl;
res= (int) (f1/f2) ;: COnven fed in to in4
coutikres<<endl;
res = f1/f2;

cout<<res;
getch ();

(Space for Answers)

Otreom.ks..
S22..inctude........... ... ***********

. ncluude.k.co.ni.a.h...
*****.
****'****** incuu.de..math.:h...
*********

**°*

*******'******

**************.
tlaat..a....%3.2ecre.men.enk....A
co.tK Ente... Coefh.c.ien
pa.t..patt
****************. . i . n . . . . 2 . . . . ,.. **'*****

********"

...sCriminant.. A....
****'*

********'**
*** ***

'*
cisCr.iminant..a)..
'*** **
**
** *************".
**
***''*
'***************
'*"
***************** ******.

3..us.ctiminon{.f.s.2*:a.)..
**'******

***'****** :***'****'****

qa...C.disc.iminanAt.)..f.C.2.*.a.)..
****************'***************** ******* '

0ut.KS..Roo.ks..ane..ARa...dffenend...kKend.1.,
****"**
******'***

******* **

*************'*
**
..Cout.K...A
**** k.Aq.SK.eadl. E2ksnd.. ***'*

*** ** ******************

*** *********.
..As.e..f... sCi.minant. )....
.... ..... *********** ** **********

.CO.LLt..s 00.t...ae..A.al.. a.me.S9nd...


1 - b C.2* 02.. ******** *
Co.Lut..SS 2.
***** ' *'***
**"°***** ***
**''******
S.1 ******
end
****** .
********
******************'**** ** *** *.* *******

Maharashtra state Board of Technical Education


Object Oricnted Programming Using C* (22316)
******************** ** *********"************************ ********************** *********************'****

******************Y*'****'************************'**** ************************ * ** ************

*7*'*****'**** '************************** * **** * * ***********.

a t..dis.crimina )..2.k.a.).. **** ** *** *********

...CoLtKs..0oS..Oe.Complex...k.dtffenenKAd.
.Cout.ss .par.t.. .i.pat.k. ond S
*****CoCut..a .A03.t.KS. .patsk.Ksnd !s

Reh...d. ** ************°*** ********** .* * *.


******* ********************

.Lutp.at. te...coetfictent. ..
***** *************** .Roo . Ra). .dffenen.. ***** *************

*********
*****************. . . . . . O.2S
. . A g E********** *** *** ** *** .*. ****************** ********.

*** *****.**************** *********** * ********************************.********************************'

* * * **"******* ******* *********** **** ***~*** ****.************ * ************** ***.

22H.include.S.i.ast.rem. ******** **.******************************* ** **

**********
.M.O.d..Ma'nc2.. * ********* ******** ********* *************************

****** .D..20. A0. . ... 1' ******* ********.

* * * *
e..Cath)....d..
******************COut.Kk.alue..atb)..C.Ld... Ke.KendL
******** ********e. a.b..C.L.d.)..
..0.tSS.alue.....th.d.*I.d.S..K.eSKend.
***************

*********'******* * * ****** *******

********** ***T.
ala .L.hc)./al.s..eK.end..
*************
e *
0tek. d).. ****'*************'***'** *********************** ******

********** ***

*********** 9.eteh.C),. *************************°* ************************* **********************************************

****************
*********************

'************************************************************************

*************

.LtRut.. alue.. at...). Sle. . .

**********************
...alue...C.At. .L.d.. .0. ********* * ****

********'**"*** ****
a.lu... ..
.Ca.t.b.).X.C.CLd. .
************'''*****
*******
**
****.

...Ua.lue. . a t . 2 . 1 .*********"****'*************'***** **** *** *********


********** *********

Maharashtra state Board of Technical Education


Object Oriented Programming Using C ++ (22316)

XIV References / Suggestions for further Reading


1. https://www.sanfoundry.com/c-plus-plus-interview-questions-experienced
references/
2. http://people.scs.carleton.ca/-dehne/projects/cpp-doc/tutorial/tutl-2.html
3. http://www.cplusplus.com/doc/tutorial/constants/
4. http://home.pacificr.com/-mmead/cs161/lesson03_07.html

XV Assessment Scheme

Performance indicators Weightage


Process related(35 Marks) 70%
Logic formation 20%
Appropriate use of Variables, constants,
20%
arithmeticexpressions and data type conversions.
Debugging ability 20%
Follow ethical practices. 10%

Product related (15 Marks) 30%

Expected Output 10%

6 Timely Submission of report 10%

7 Answer to sample questions 10%

Total (50 Marks) 100%

List of Students /Team Members

2.

Dated signature
Marks Obtained
of Teacher
Process Product
Total(50)
Related(35) Related(15)

Maharashtra state Board of Technical Education

You might also like