ASSIGMENT

7
ASSIGMENT : C++ PROGRAMMING QUESTIONS 1. Who is Wri tten C++ Bjarne Stroustrup, a Danish computer scientist, b egan his work on C++'s predecessor "C with Classes" in 199! he moti#ation $or creating a new language originated $rom Stroustrup's e%perience in programming $or his &h!D! thesis! Stroustrup $ound that Simula had $eatures that were #er help$ul $or large so$tware de#elopment, but the language was too slow $or practical use, while BC&( was $ast but too low)le#el to be suitable $or large so$tware de#elopment! *hen Stroustrup started working in Bell (abs, he had the problem o$ anal-ing the ./0 kernel with respect to distributed computing! 2emembering his &h!D! e%perience, Stroustrup set out to enhance the C language with Simula)like $eatures ! 34  C was chosen because it was general)purpose, $ast, portable and widel used! s well as C and Simula's in$luences, other languages also in$luenced C++, including (56( 78, da, C(. and (! 0nitiall, the class, deri#ed class, strong tping, inlining and de$ault argument $eatures were added to C #ia Stroustrup's "C with Classes" to C compiler, Cpre! 0n 198:, it was renamed $rom C with Classes to C++ ;"++" being the increment operator in C<! /ew $eatures were added including #irtual $unctions, $unction name and operator o#erloading, re$erences, constants, tpe)sa$e $ree)store memor allocation ;new=delete<, impro#ed tpe checking, and BC&( stle single)line comments with two $orward slashes ; // <, as well as the de#elopment o$ a proper compiler $or C++, C$ront! 0n 198>, the $irst edition o$ The C++ Programming Language  was released, which became the de$initi#e re$erence $or the language, as there was not et an o$$icial standard! he $irst commercial implementation o$ C++ was released in 6ctober o$ the same ear! 4 0n 1989, C++ ?!@ was released, $ollowed b the updated second edition o$ The C++ Programming Language  in 1991! 31@4  /ew $eatures in ?!@ included multiple inheritance, abstract classes, static member $unctions, const member $unctions, and protected members! 0n

description

ass igment

Transcript of ASSIGMENT

7/17/2019 ASSIGMENT

http://slidepdf.com/reader/full/assigment-568be573eaf9d 1/7

ASSIGMENT: C++ PROGRAMMING

QUESTIONS

1.Who is Written C++

Bjarne Stroustrup, a Danish computer scientist, began his work on C++'s predecessor "C

with Classes" in 199! he moti#ation $or creating a new language originated $rom Stroustrup's

e%perience in programming $or his &h!D! thesis! Stroustrup $ound that Simula had $eatures that

were #er help$ul $or large so$tware de#elopment, but the language was too slow $or practical

use, while BC&( was $ast but too low)le#el to be suitable $or large so$tware de#elopment! *hen

Stroustrup started working in Bell (abs, he had the problem o$ anal-ing

the ./0 kernel with respect to distributed computing! 2emembering his &h!D! e%perience,

Stroustrup set out to enhance the C language with Simula)like $eatures!34

 C was chosen becauseit was general)purpose, $ast, portable and widel used! s well as C and Simula's in$luences,

other languages also in$luenced C++, including (56( 78, da, C(. and (!

0nitiall, the class, deri#ed class, strong tping, inlining and de$ault argument $eatures were added

to C #ia Stroustrup's "C with Classes" to C compiler, Cpre!

0n 198:, it was renamed $rom C with Classes to C++ ;"++" being the increment operator in C<!

/ew $eatures were added including #irtual $unctions, $unction name and operator o#erloading,

re$erences, constants, tpe)sa$e $ree)store memor allocation ;new=delete<, impro#ed tpe

checking, and BC&( stle single)line comments with two $orward slashes ; // <, as well as the

de#elopment o$ a proper compiler $or C++, C$ront!

0n 198>, the $irst edition o$ The C++ Programming Language was released, which became the

de$initi#e re$erence $or the language, as there was not et an o$$icial standard! he $irst

commercial implementation o$ C++ was released in 6ctober o$ the same ear!4

0n 1989, C++ ?!@ was released, $ollowed b the updated second edition o$ The C++

Programming Language in 1991!31@4 /ew $eatures in ?!@ included multiple inheritance, abstract

classes, static member $unctions, const member $unctions, and protected members! 0n

7/17/2019 ASSIGMENT

http://slidepdf.com/reader/full/assigment-568be573eaf9d 2/7

199@, The Annotated C++ Reference Manual  was published! his work became the basis $or the

$uture standard! (ater $eature additions included templates, e%ceptions, namespaces, new casts,

and a boolean tpe!

 $ter the ?!@ update, C++ e#ol#ed relati#el slowl! 0n ?@11, the C++11 standard was released,adding numerous new $eatures, enlarging the standard librar $urther, and pro#iding more

$acilities to C++ programmers! $ter a minor C++1A update, released in December ?@1A, #arious

new additions are planned $or ?@1!

?!State statements below and give an example applicationin C++ Program.

 a!Go To

A goto statement provides an unconditional jump from the goto to a labeled

statement in the same function.

goto label;

..

.

label: statement;

b!While

A while loop statement repeatedly executes a target statement as long as a

given condition is true.

whle!"on#ton$

%

  statement!s$;

&

7/17/2019 ASSIGMENT

http://slidepdf.com/reader/full/assigment-568be573eaf9d 3/7

c!Break and Continue

The continue statement works somewhat like the break statement.

Instead of forcing termination, however, continue forces the next

iteration of the loop to take place, skipping any code in between.

For the for loop, continue causes the conditional test and increment

portions of the loop to execute. For the while and do...while loops,

program control passes to the conditional tests.

'n"l(#e )ost*eam

(sng names,a"e st#;

 

nt man !$

%

  -- o"al /a*able #e"la*aton:

  nt a 0 12;

  -- #o loo, e3e"(ton

  #o

  %

  4! a 00 15$

  %

  -- s6, the te*aton.

  a 0 a + 1;

  "ontn(e;

  &

  "o(t )) 7/al(e o4 a: 7 )) a )) en#l;

  a 0 a + 1;

  &whle! a ) 82 $;

 

*et(*n 2;

&

The break statement has the following two usages in !!"

7/17/2019 ASSIGMENT

http://slidepdf.com/reader/full/assigment-568be573eaf9d 4/7

• #hen the break statement is encountered inside a loop, the loop is

immediately terminated and program control resumes at the next statement

following the loop.

• It can be used to terminate a case in the switch statement $covered in the

next chapter%.

If you are using nested loops $i.e., one loop inside another loop%, the

break statement will stop the execution of the innermost loop and start

executing the next line of code after the block.

'n"l(#e )ost*eam

(sng names,a"e st#;

 

nt man !$

%

  -- o"al /a*able #e"la*aton:

  nt a 0 12;

  -- #o loo, e3e"(ton

  #o

  %

  "o(t )) 7/al(e o4 a: 7 )) a )) en#l;

  a 0 a + 1;

  4 ! a  15$

  %

  -- te*mnate the loo,

  b*ea6;

  &

  &whle! a ) 82 $;

 

*et(*n 2;

&

d.While True

7/17/2019 ASSIGMENT

http://slidepdf.com/reader/full/assigment-568be573eaf9d 5/7

#include <iostream>

using namespace std;

int main() {

  int number, i = 1, factorial = 1;

  cout<< "Enter a positive integer ";

  cin >> number;

 

!ile ( i <= number) {

  factorial = i; $$factorial = factorial i;

  %%i;

  &

  cout<<"'actorial of "<<number<<" = "<<factorial;

  return ;

&

e !ile loop cec*s !eter te test e+pression is true or not -f it is true, code$s

inside te bod. of !ile loop is e+ecuted,tat is, code$s inside te braces { & aree+ecuted en again te test e+pression is cec*ed !eter test e+pression is true or

not is process continues until te test e+pression becomes false

E ) Do / While :

7/17/2019 ASSIGMENT

http://slidepdf.com/reader/full/assigment-568be573eaf9d 6/7

do {

  statement/s;

}

while (test expression);

e statement$s inside bod. of loop is e+ecuted at least once, tat is, te statement$s inside

 braces { & is e+ecuted at least once en te test e+pression is cec*ed -f te test e+pression

is true, te bod. of loop is e+ecuted is process continues until te test e+pression becomes

false /ince te bod. of loop is placed before te test e+pression in do!ile loop, te bod.

of loop is e+ecuted at least once

e.Do/While

&nlike for and while  loops, which test the loop condition at the top of 

the loop, the do...while loop checks its condition at the bottom of the

loop.

A do...while loop is similar to a while loop, except that a do...while loop

is guaranteed to execute at least one time.

#o

%

  statement!s$;

&whle! "on#ton $;

f. Jump/Loop

for(initiali0ation statement; test e+pression; update statement) {

code$s to be e+ecuted;

&

7/17/2019 ASSIGMENT

http://slidepdf.com/reader/full/assigment-568be573eaf9d 7/7

e initiali0ation statement is e+ecuted onl. once at te beginning of te for loop

en te test e+pression is cec*ed b. te program -f te test e+pression is false, for

loop is terminated ut if test e+pression is true ten te code$s inside bod. of for loop

is e+ecuted and ten update e+pression is updated is process repeats until test

e+pression is false

g.if'else

An if  statement can be followed by an optional else statement, which

executes when the boolean expression is false.

4!boolean9e3,*esson$

%

  -- statement!s$ wll e3e"(te 4 the boolean e3,*esson s t*(e

&

else

%

  -- statement!s$ wll e3e"(te 4 the boolean e3,*esson s 4alse

&