C++ is an object-oriented language that is the successor to the procedural language C. It was developed in the 1970s and includes many of C's features while adding object-oriented programming concepts like inheritance, function overloading, and method overloading. The general form of a C++ program includes preprocessor directives, function declarations and definitions, and returns an integer value from the main function. C++ supports various data types, loops, comments, and identifiers to write programming code.
C++ is an object-oriented language that is the successor to the procedural language C. It was developed in the 1970s and includes many of C's features while adding object-oriented programming concepts like inheritance, function overloading, and method overloading. The general form of a C++ program includes preprocessor directives, function declarations and definitions, and returns an integer value from the main function. C++ supports various data types, loops, comments, and identifiers to write programming code.
C++ is an object-oriented language that is the successor to the procedural language C. It was developed in the 1970s and includes many of C's features while adding object-oriented programming concepts like inheritance, function overloading, and method overloading. The general form of a C++ program includes preprocessor directives, function declarations and definitions, and returns an integer value from the main function. C++ supports various data types, loops, comments, and identifiers to write programming code.
C++ is an object-oriented language that is the successor to the procedural language C. It was developed in the 1970s and includes many of C's features while adding object-oriented programming concepts like inheritance, function overloading, and method overloading. The general form of a C++ program includes preprocessor directives, function declarations and definitions, and returns an integer value from the main function. C++ supports various data types, loops, comments, and identifiers to write programming code.
What is C++ C++ is a object-oriented language. It is the “successor” to C, a procedural language. (the “++” is called the successor operator in C++) C was derived from a language called B which was in turn derived from BCPL C++ was developed in the 1970’s by Dennis Ritchie of AT & T Bell Labs. Most of C is a subset of C++ Difference Between C & C++ C++ is an object oriented programming but C is a procedure oriented programming. C is a super set C++. C can’t support inheritance, function overloading, method overloading etc. but it is possible in C++. In C- program the main function could not return a value but in C++ should return value. Advantages Integrated with programming language Automatic method storage(when available) User- defined types Complex data readily processed Automatic persistent object IDs Single-level memory. C++ keywords
Each keyword has a predefined purpose in the language.
keywords cannot be used as variable and constant names!!. bool, break, case, char, const, continue, do, default, double, else, extern, false, float, for, if, int, long, namespace, return, short, static, struct, switch, typedef, true, unsigned, void, while General form of a C++ program // Program description #include directives int main() { constant declarations variable declarations executable statements return 0; } C++ compiler directives
Compiler directives appear in blue in Visual C++.
The #include directive tells the compiler to include some already existing C++ code in your program. The included file is then linked with the program. There are two forms of #include statements: #include <iostream> //for pre-defined files
#include "my_lib.h" //for user-defined files
C++ identifiers Identifiers appear in black in Visual C++. ◦ An identifier is a name for a variable, constant, function, etc. ◦ It consists of a letter followed by any sequence of letters, digits, and underscores. ◦ Examples of valid identifiers: First_name, age, y2000, y2k ◦ Examples of invalid identifiers: 2000y ◦ Identifiers cannot have special characters in them. For example: X=Y, J-20, ~Ricky,*Michael are invalid identifiers. ◦ Identifiers are case-sensitive. For example: Hello, hello, WHOAMI, WhoAmI, whoami are unique identifiers. C++ comments Comments appear in green in Visual C++. Comments are explanatory notes; they are ignored by the compiler. There are two ways to include comments in a program:
// A double slash marks the start of a
//single line comment.
/* A slash followed by an asterisk marks
the start of a multiple line comment. It ends with an asterisk followed by a slash. */ Looping in Programming Loops in programming are used to repeat a block of code. Being able to have your programming repeatedly execute a block of code is one of the most basic but useful tasks in programming -- many programming programs or programming websites that produce extremely complex output are really only executing a single task many times. A loop in programming lets you write a very simple statement to produce a significantly greater result simply by repetition. We can create a loop block using for loop,do while loop ,while loop and switch case. Data types When programming, we store the variables in our computer's memory, but the computer has to know what kind of data we want to store in them, since it is not going to occupy the same amount of memory to store a simple number than to store a single letter or a large number, and they are not going to be interpreted the same way. The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer (generally an integer between 0 and 255). In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers. NAME DESCRIPTION SIZE RANGE CHAR character or small integer 1 Byte signed -128 to 127 unsigned 0 to 255 Short int Short Integer 2 bytes signed -32768 to 32768 unsigned 0 to 65535 Int integer 4 bytes signed -2147483648 to 2147483647 unsigned 0 to 4294967295 Long int long integer 4 bytes signed -2147483648 to 2147483647 unsigned 0 to 4294967295 Bool Boolean value.It can 1 byte true and false take to or one values true or false. Float floating point number 4 bytes +/- 3.4e +/-38(~7 digits) Double Double precision 8 bytes +/- 1.7e +/-308(~15 digits) floating point number Long double Long double precision 8 bytes +/- 1.7e +/-308(~7 digits) floating point number Wchar_t wide character. 2 or 4 bytes 1 wide character 1.Program to find maximum of 10 values stored in array. #include<iostream.h> #include<conio.h> void main() { OUTPUT int a[10],i,j,m,loc=0; Enter 10 elements of array: clrscr(); 5 cout<<"enter 10 elements of array:"; 8 for(i=0;i<=9;i++) 2 { 12 cin>>a[i]; 65 } m=a[0]; 36 for(j=1;j<=9;j++) 98 { 45 if(a[j]>m) 25 { 96 m=a[j]; loc=j+1; Max value is: 98 } Its location is: 7 } cout<<"max value is:"<<m; cout<<“Its location is:"<<loc; getch(); } #include<iostream.h> 4.program to find smallest of 10 values stored in an #include<conio.h> array. class smallest { public: int a[10],j,min; int calculate_smallest() { cout<<"enter 10 elements of array:"; for(int i=0;i<=9;i++) { cin>>a[i]; OUTPUT } Enter 10 elements of array: min=a[0]; //0th element is set as minimum values for(j=1;j<=9;j++) -5 { 8 if(a[j]<min) 2 { min=a[j]; 12 }} 65 return min; 36 } 98 } void main() { 45 int min1; 25 clrscr(); 96 smallest s1; min1=s1.calculate_smallest(); cout<<“Smallest of ten values is:"<<min1; Smallest of ten values is: -5 getch(); }