Você está na página 1de 8

ASSIGNMENT C++ PROGRAMMING

1. WHAT IS C++.
C++ (pronounced cee plus plus) is a general purpose programming language. It
has imperative, object-oriented and genericprogramming features, while also providing the facilities
for low level memory manipulation.
It is designed with a bias for systems programming (e.g. embedded systems, operating system
kernels), with performance, efficiency and flexibility of use as its design requirements. C++ has also
been found useful in many other contexts, including desktop applications, servers (e.g. ecommerce, web search, SQL), performance critical applications (e.g. telephone switches, space
probes) and entertainment software, such as video games.[3]
It is a compiled language, with implementations of it available on many platforms. Various
organizations provide them, including theFSF, LLVM, Microsoft and Intel.
C++ is standardised by the International Organization for Standardization (ISO), which the latest
(and current) having being ratified and published by ISO in September 2011 as ISO/IEC
14882:2011 (informally known as C++11).[4] The C++ programming language was initially
standardised in 1998 as ISO/IEC 14882:1998, which was then amended by the C++03, ISO/IEC
14882:2003, standard. The current standard (C++11) supersedes these, with new features and an
enlarged standard library.
Before standardization (1989 onwards), C++ was developed by Bjarne Stroustrup at Bell Labs,
starting in 1979, who wanted an efficient flexible language (like C) that also provided high level
features for program organization.
Many other programming languages have been influenced by C++, including C#, Java, and newer
versions of C (after 1998)

2. WHO IS WRITTEN C++?


Bjarne Stroustrup

Bjarne Stroustrup
Born

December 30, 1950 (age 63)


Aarhus, Denmark

Residence

New York, United States [1]

Institutions

Aarhus University
University of Cambridge
Texas A&M University
Bell Labs
Morgan Stanley
Columbia University

Alma mater

Aarhus University (MSc)


Churchill College, Cambridge(PhD)

Thesis

Communication and control in


distributed computer systems (1979)

Doctoral
advisor

David Wheeler

Known for

Creating C++

Notable
awards

Grace Murray Hopper Award(1993)


IEEE Computer Society Computer
Entrepreneur Award (2004)
William Procter Prize for Scientific
Achievement (2005)
Dr. Dobb's Excellence in Programming
award (2008)

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

3. DESCRIBETHE PURPOSE OF THE FOLLOWING SYNTAX AND GRAMMAR.

A) #
Line beginning with a hash sign(#)are directives for the preprocessor. They are not regular

code lines with expressions but indications for the compiler's preprocessor

B) #include
-

Beginning with a hash sign (#) are directives for the preprocessor. They are not regular
code lines with expressions but indications for the compiler's preprocessor. In this case
the directive #include

C) Iostream.h
-

Usually the compiler inserts the contents of a header file called iostream into the
program. Where it puts it depends on the system. The location of such files may
be described in your compiler's documentation. A list of standard C++ header
files is in the standrat headers reference

D) Int main()
-

Given the name main. Such a named block of code is called a function in C++
parlance. The contents of the block are called the body of the function.

E) Function
-

Allow to structure program in segment of code to perfom individual taks.

F) <<
-

The << operator insert the data that follows it into the stream that preceds it .

G) Hello World\n
-

This line is a C++ statement. C++ statements are terminated by a semicolon (;).
Within the statement <<, called the insertion operator is used to output the string
using the std::cout stream.

H) \n
-

\n is the newline character , when the newline character is output to the console
breaks a newline .

I) ;
-

J)

This character is used to mark the ends in facts it must be include at the end of all
expression statesments in all c++ programs (one of the most common syntax
errors is indeed to forget to include some semicolon after a statements )

Return0;
-

The return statement causes the main function to finish. return may be
followed by a return code (in ourexample is followed by the return code 0) . A
return code of 0 for the main function is generally interpreted as the program
worked as expected without any errors during its execution. This is the most
usual way to end a C++ console program.You may have noticed that not all
the lines of this program perform actions when the code is executed. There
were lines containing only comments (those beginning by //). There were
lines with directives for the compiler's preprocessor (those beginning by #).
Then there were lines that began the declaration of a function (in this
case,the main function) and, finally lines with statements (like the insertion
into cout), which were all included within the block delimited by the braces
({}) of the main function.The program has been structured in different lines in
order to be more readable, but in C++, we do not have strict rules on how to
separate instructions in different lines.

4. GIVE 5 MATHEMATICAL SYMBOL AND 6 RELATIONAL OPERATORS.


i.
MATHEMATICAL OPERATORS
SYMBOL

MEANING

1)+

ADDITION OR UNRY PLUS

2)-

SUBTRACTION OR UNARY MINUS

3)*

MULTIPLICATION

4)/

DIVISION

5)%

REMAINDER AFTER DIVISION

ii.

RELATIONAL OPERATORS
SYMBOL

MEANING

1)==

EQUAL TO

2)>

GREATER THAN

3)<

LESS THAN

4)!=

NOT EQUAL TO

5)>=

GREATER THAN OR EQUAL TO

6)<=

LESS THAN OR EQUAL TO

5. STATESTATEMENTS BELOW AND GIVE AN EXMPLE APPLICATION IN C++


PROGRAM.(14m)
A) Go to
-

The goto statement is a control flow statement that causes the CPU to jump
to another spot in the code. This spot is identified through use of
a statement label.

// goto_statement.cpp
#include <stdio.h>
int main()
{
int i, j;
for ( i = 0; i < 10; i++ )
{
printf_s( "Outer loop executing. i = %d\n", i );
for ( j = 0; j < 2; j++ )
{
printf_s( " Inner loop executing. j = %d\n", j );
if ( i == 3 )
goto stop;
}
}
// This message does not print:
printf_s( "Loop exited. i = %d\n", i );
stop:
printf_s( "Jumped to stop. i = %d\n", i );
}

B) While
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)

// do_while_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf_s("\n%d",i++);
} while (i < 3);
}

C) Break and Continue

intnPrinted = 0;

C) 1
D) 2
E) 3
F) 4
G) 5
H) 6
I) 7
J) 8
K) 9
L) 10
M) 11
N) 12
O) 13

for(intiii=0; iii < 100; iii++)


{
// messy!
if((iii % 3) && (iii % 4))
{
cout<< iii <<endl;
nPrinted++;
}
}

cout<<nPrinted<< " numbers were found"<<endl;

However, this can be rewritten as the following, which is easier to read:

1
2
3
4
5
6
7

intnPrinted
= 0;
k) //
do_while_statement.cpp
l) #include <stdio.h>
m) int main()
for(intiii=0;
n) { iii < 100; iii++)
o) int i = 0;
{
p)
do
// ifq)the number
is divisible by 3 or 4, skip this iteration
{
r) printf_s("\n%d",i++);
if((iii
% 3)==0 || (iii % 4)==0)
s)
} while (i < 3);
continue;
t) }

8
cout<< iii <<endl;

nPrinted++;

10
}

11
12
13

cout<<nPrinted<< " numbers were found"<<endl;

D) While true
- Excutes statements repeatedly until the spectified termination condition evaluates

E) Do/While
- Excutes statements repeatedly until the spectified termination condition the
evaluates to zeros

F) Jump/Loop
- Exucutes a sequence of statements multiple times and abbreviates the code that
manages the loop variable.
G) If/else
- An if statements can be followed by an optional else statements , which executes
when the boolen expression if false

Você também pode gostar