You are on page 1of 6

ASSIGNMENT : C++ PROGRAMMING

(BJARNE STROUSTRUP)

1. Who is Written C++?


Bjarne Stroustrup born 30 December 1950) is a Danish computer scientist, most notable for the creation and
development of the widely used C++ programming language.He is a Distinguished Research Professor and holds the
College of Engineering Chair in Computer Science at Texas A&M University, a visiting professor at Columbia
University, and works at Morgan Stanley.

Education
Stroustrup has a master's degree in mathematics and computer science (1975) from Aarhus University, Denmark,
and a Ph.D. in computer science (1979) from the University of Cambridge, England. His thesis advisor in Cambridge
was David Wheeler.

Career
Stroustrup began developing C++ in 1978 (then called "C with Classes"), and, in his own words,
"invented C++, wrote its early definitions, and produced its first implementation...chose and
formulated the design criteria for C++, designed all its major facilities, and was responsible for the
processing of extension proposals in the C++ standards committee. Stroustrup also wrote a textbook
for the language, The C++ Programming Language. Stroustrup was the head of AT&T Bell Labs' Largescale Programming Research department, from its creation until late 2002. Stroustrup was elected
member of the National Academy of Engineering in 2004. He is a Fellow of the ACM (1994) and
an IEEE Fellow. He works at Texas A&M University as a Distinguished Professor where he holds the
College of Engineering Endowed Chair in Computer Science. He is also a visiting faculty in Computer
Science Department at Columbia University. ITMO University noble doctor since 2013. In 2015, he was
made a Fellow of the Computer History Museum for his invention of the C++ programming language.

Publications

Stroustrup has written or co-written a number of publications including the following books.

A Tour of C++ by Bjarne Stroustrup Addison-Wesley Professional, 2013. ISBN 978-0321958310.


Programming: Principles and Practice Using C++ by Bjarne Stroustrup Addison-Wesley Professional;
1st edition (29 December 2008); ISBN 0-321-54372-6.
The C++ Programming Language by Bjarne Stroustrup Addison-Wesley Pub Co; 4th edition (23 May
2013); ISBN 0-321-563840.
The Design and Evolution of C++ by Bjarne Stroustrup Addison-Wesley Pub Co; 1st edition (29 March
1994); ISBN 0-201-54330-3.
The Annotated C++ Reference Manual by Margaret A. Ellis & Bjarne Stroustrup Addison-Wesley Pub
Co; (1 January 1990); ISBN 0-201-51459-1.

Website
www.stroustrup.com
parasol.tamu.edu/people/bs

2.

State statement below and give an example application in C ++ Program.

Syntax of goto Statement


In syntax above, label is an identifier. When goto label; is encountered, the control of program jumps
to label: and executes the code below it.

Example 1: goto Statement


/* C++ program to demonstrate the working of goto statement. */
/* This program calculates the average of numbers entered by user. */
/* If user enters negative number, it ignores that number and
calculates the average of number entered before it.*/
# include <iostream>
using namespace std;
int main() {
fl oat num, average, sum = 0.0;
int i, n;
cout<<"Maximum number of inputs: ";
cin>>n;
for(i=1; i <= n; ++i) {
cout<<"Enter n"<<i<<": ";
cin>>num;
if(num < 0.0) {
goto jump; /* Control of the program moves to jump; */
}
sum += num;
}
jump:
average=sum/(i-1);
cout<<"\nAverage = "<<average;
return 0;
}

b.) C programming loops


:Loops causes program to execute the certain block of code repeatedly until some conditions are
satisfi ed, i.e., loops are used in performing repetitive work in programming. Suppose you want to
execute some code/s 10 times. You can perform it by writing that code/s only one time and repeat
the execution 10 times using loop. There are 3 types of loops in C programming
1.

for loop

2.

while loop

3.

do...while loop

Example of while loop


Write a C program to fi nd the factorial of a number, where the number is entered by user.
(Hints: factorial of n = 1*2*3*...*n
/*C program to demonstrate the working of while loop*/
#include <stdio.h>
int main(){
int number,factorial;
printf("Enter a number.\n");
scanf("%d",&number);
factorial=1;
while (number>0){
/* while loop continues util test condition number>0 is true */
factorial=factorial*number;
--number;
}
printf("Factorial=%d",factorial);
return 0;
}

Example of do...while loop


Write a C program to add all the numbers entered by a user until user enters 0.
/*C program to demonstrate the working of do...while statement*/
#include <stdio.h>
int main(){
int sum=0,num;
do
/* Codes inside the body of do...while loops are at least executed once. */
{
printf("Enter a number\n");
scanf("%d",&num);
sum+=num;
}

while(num!=0);
printf("sum=%d",sum);
return 0;
}

c.) Break and Continue

Example 1: C++ break


C++ program to add all number entered by user until user enters 0.
// C++ Program to demonstrate working of break statement
#include <iostream>
using namespace std;
int main() {
fl oat number, sum = 0.0;
while (true) {
// test expression is always true
cout<<"Enter a number: ";
cin>>number;
if (number != 0.0) {
sum += number;
}
else {
break;
// terminating the loop if number equals to 0.0
}
}
cout<<"Sum = "<<sum;
return 0;
}

d) While True
The while loop in C/C++ is very similar to the for loop. The for statement contains two semicolons, which allows placement of
the initialization statement, the negation of the termination condition and the iterative statement in it. However, the while loop
allows placement of only the condition so the other two statements must be placed outside the while statement.

e.) do / while
The while loop checks whether the test expression is true or not. If it is true, code/s inside the body of while
loop is executed,that is, code/s inside the braces { } are executed. Then again the test expression is checked
whether test expression is true or not. This process continues until the test expression becomes false.

f.) Jump/ Loop


How for loop works in C programming?
The initialization statement is executed only once at the beginning of the for loop. Then the test expression is
checked by the program. If the test expression is false, for loop is terminated. But if test expression is true then
the code/s inside body of for loop is executed and then update expression is updated. This process repeats until
test expression is false.
This flowchart describes the working of for loop in C programming.

g.) if / else
The if statement checks whether the text expression inside parenthesis () is true or not. If the test expression is
true, statement/s inside the body of if statement is executed but if test is false, statement/s inside body ignored.

You might also like