CP-Lecture - 04-06 (Basic Structure of A C++ Program)
CP-Lecture - 04-06 (Basic Structure of A C++ Program)
CONCEPTS
Lecture: 04-06
int main()
{
cout<<"14 Computer Systems";
getch();
return 0;
}
Anatomy of C++ basic program
Output on monitor screen
Anatomy of C++ basic program
Using Namespace
Statement
using namespace std; Standard Namespace
Return Type
Function Name
main Function int main ( )
Closing Parenthesis
Opening Parenthesis
Anatomy of C++ basic program
Console Output
Insertion / put-to operator
Opening Brace {
cout Statement cout << “14 Computer Systems” ;
Get Character Terminator
Function
getch();
String Literal
Return Statement return 0;
Closing Brace }
Outputting with cout
• The getch function is used to get one character from the keyboard.
• Whenever the computer encounters getch function, it will wait for the user
to press any key from the keyboard.
• Once the user presses any key on the keyboard that will be get by the getch
function.
• In this program it is used to hold the screen so that we can view the output
of the program.
getch()function
Header file which are part of C as well as C++ have the extension .h
Header files which are only the part of C++ does not have extension .h
Header files
Processor Processing
The names like cout, cin, endl can be used in either of two ways.
int main()
{
cout<<"14 Computer Systems"<<endl;
cout<<“MUET";
getch();
return 0;
}
Namespaces
• In fully qualified name, every name will be prepended with namespace and :: (double
colon sign) as std::cout, std::cin, std::endl.
• Here we do not have to write the using namespace statement.
#include<iostream>
#include<conio.h>
int main()
{
std::cout<<"14 Computer Systems"<<std::endl;
std::cout<<“MUET";
getch();
return 0;
}