First CPP Assignment
First CPP Assignment
First CPP Assignment
SECTOIN
Introduction Of C++
Uses OF C++
1: C++ is used To make Desktop Application , For developing games, For design
data base , For Develop Web Browsers , it is development of other languages , used to make Medicine
Application , Compiler are also develop In C++ language .
First the source code sent to the header files . The preprocessor is responsible to convert preprocessor
directives into their respective values. The preprocessor generates an expanded source code.
Secound Then This Expended Source code send to the compiler . then Compiler change Source Code
intoAssembly Code .
Then this Assemble code is send to the Assembler . And the Assembler convert this code into Object
Code. Now a simple.obj file
Then the object code is send to the linker which link to the header file (preprocess directive). Then it
converted into executable file . mean convert into Sample.exe.
Then this exactable code send to the loader it load it to the memory and execute it .
3.main function
Example
#header file
void main()
{
Body of program
}
#include <iostream>
int main()
{
std::cout << "Hello World!";
return 0;
}
We include this file of directive in our program . here we use <iostream> directive. It is used for getting
Input or output of the program . in this example <iostream > is used for output .
2: The second and third line is blank .. blank line doesn’t effect program .
3: In third Line we declare a function . there we use function . function will be discuss latter because it’s
a beginning of C++ . Our basic Program start after this line . And Every Function has parentheses () . it
may be Empty and maybe filled .
4 &7 : we have to make our program inside the these braces {}. Main program Start inside these braces
5 : The Fifth line Is a C++ statement . every Statement must start with (std::) .
First, std::cout, which identifies the standard character output device (usually, this is the computer
screen). I use cout tag for getting output . and << are insertion operator .
If we Use [ using namespace std ] . then we don’t need to write (std::) in any C++ statement .
OK Example End ..
In Input Statement Is a statement in Which We get Information After seeing Output . For Example if we
wanna take anything for user We use Input Statement .And Another Example When we made a program
of Admission Form . In This form we get information from user .
Cin tag is used for input statement .And the operator for input statement is ( << ).
Good Example :
Now I making A program in which User Enter Any Number and then press enter then will be double .
#include <iostream>
Int i ,
Cin >> I ;
System(pause);
The Statements That are used to get Output On the screen are Output statement in C++ .If we wanna print
any string or anything we use Output statement . In C language We use print F tag to get output , but in
C++ we use cout tag . The Syntax of this tag is . for example WE wanna print Hello word
now in this example we Use cout . which mean Output statement tag and, and we use ( << ).these are
insertion operators . The << operator inserts the data that follows it dad the stream tdadaachat precedes
it. In the examples aabove, it d the literal string Output dsentence, the d 120, awnd the vfalue of
vaaariable x into the a out dput stream cout. Notice that the sentence in w first statement is enclosed in c
ddd (") because it is a string literal, while in the last one, x is not. The double quoting is what w the
differdnce; when the text is enclosed between them, the text is printed as it is .we can Also say that the
things inside Quates are Print As it is .
example
#include <iostream>
using namespace std;
int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its triple is " << i*3<< ".\n";
return 0;
}
……………
#include <iostream>
int main() {
char Name[30];
…..
The basic (fundamental) data and its types provided by c++ and c languages are integral, floating point
and void data type bool and some other but important are dicuss here. Among these data types, the integer
and float types of data types can be preceded by several types of modifier. These modifiers ( are also
known as type qualifiers) are the keywords that alter either sizes or ranges and both of the data and
datatypes. The various modifiers are short, long, signed and unsigned, double and etc . By default the
modifier is signed. The datatype in C++ are already predefined . we can make data type but it is
next level of programming . There are many types of data type Used for specific function in C
language and C++ . So There are No difference in Data type Of both languages C and C++. The
Data type used because these are tags In which values are stored And these values have specials
cells in Storage . Some type of data take 4 bytes some 8 some 16 etc .
We cannot Mix any data type in any data type . program not work properly, may be answer will
be wrong .
1 ) INT :- Int data type are used to store integer value . it take 4 bytes .
bool b = true;
5 ) Char: Characters refers to the alphabets, numbers and other thing like characters (such as {, @, #, etc.)
defined in the ASCII character set. In C++, the char data type is also treat as an integer type of data as the
characters are internaly stored as integers that range in value from -128 to 127. The char data type
occupies 1 byte of memory and no more than 1 byte . (char holds only one character at a time).
Variable are used in C++,where we need storage for any value,which will change in a Program.
Variable can be declared in multiple ways each with different memory requirments and functioning
Variable is the name of memory location allocated by the compiler depending upon the datatype of the
variable
Syntax :
Datat type variable name;
data type variable name, variable name, variable name; etc
Declaration of Varible
// variable definition
int width, height, age;
char letter;
float area;
double d;
Variable Initialization
In initialization We give value to to the variable . very simple this is . this value may be change or may
not be in a program . now I will give you example of Variable initialization .
Example
// declaration and initialization program
Float m; // declaration
int n ; // declaration
m = 10.1; // initialization
n = 39 ; // initialization
Now few examples of variable
Example:
#include <iostream>
using namespace std;
int main()
{
int a =4 ;
int b = 2;
int mul;
mul= a * b;
cout << mul;
}
Example
#include <iostream>
using namespace std;
Age =15;
……….