EXERCISE SHEET ASSIGNMENT IN C++ PROGRAMMING Questions 1.What is C++? C++ is a general purpose programming language. It has imperative, object oriented and generic programming features, while also providing the facilities for low level memory manipulation. 2.Who is written C++? Bjarne StroustrupoBjarne 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, [4] a visiting professor at Columbia University, and works at Morgan Stanley. Bjarne Stroustrup 3.Describe the main purpose of the following syntax and grammar# oLines 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. #include oTells the pre-processor to include a standard file iostream.h oThis specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
o This line corresponds to the beginning of the definition of the main function. The main
function is the point by where all C++ programs start their execution, independently of
its location within the source code.
Function
o Allow to structure program in segment of code to perform individual tasks.
cout
o
cout represents the standard output stream in C++, and the meaning of the entire
statement is to insert a sequence of characters.
<<
o The << operator inserts the data that follows it into the stream that precedes it.
“Hello world\n”
o This line is a C++ statement. C++ strings are enclosed within double quotes ("). The
quotes themselves are not part of the string and hence not printed. The sequence \n is
used within a string to indicate the end of the current line. Though the sequence is
represented by two characters, it takes up only one character's worth of memory space.
Hence the sequence \n is called the newline character. The actual procedure to start anew line is system-dependent but that is handled by the C++ standard library
transparent to you.
\n
o '\n' is the newline character. When the newline character is output to the console, the
console breaks a new line.
;
o This character is used to mark the end of the statement and in fact it must be included at
the end of all expression statements in all C++ programs (one of the most common
syntax errors is indeed to forget to include some semicolon after a statement)
Return 0
o The return statement causes the main function to finish. Return may be followed by a
return code (in our example 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.