├── .vscode └── settings.json ├── 04_hello_world.cpp ├── 31_class.cpp ├── 30_header1.cpp ├── README.md ├── 05_outputting_text.cpp ├── 46_refrence.cpp ├── 20_for.cpp ├── 45_refrencs.cpp ├── 33_string_stream.cpp ├── 43_char_array.cpp ├── 15_bad_float.cpp ├── 44_reversing_aString.cpp ├── 54_encapsulation.cpp ├── 13_if.cpp ├── 24_sixeof_array.cpp ├── 07_USER_INPUT.cpp ├── 17_while_loops.cpp ├── 42_pointer_arithmatic.cpp ├── 23_multidimenional_array.cpp ├── 27_functions.cpp ├── 19_do_while.cpp ├── 53_inheritance.cpp ├── 10_int_type.cpp ├── 47_copy_constructor.cpp ├── 06_variables.cpp ├── 21_break_continue.cpp ├── 25_sizeofmultidimensionalarray.cpp ├── 29_parameter.cpp ├── 14_if_else.cpp ├── 21_break_continue_pass.cpp ├── 41_pointers_and_arrays.cpp ├── 39_pointers.cpp ├── 48_new_operator.cpp ├── 26_switch.cpp ├── 28_return.cpp ├── 11_float_type.cpp ├── 51_array_function.cpp ├── 50_allocating_memories.cpp ├── 49_createClassByFuncTion.cpp ├── 22_array.cpp ├── 40_arthimatic.cpp └── 16_conditions.cpp /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "iostream": "cpp" 4 | } 5 | } -------------------------------------------------------------------------------- /04_hello_world.cpp: -------------------------------------------------------------------------------- 1 | //1st program 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | // this is comment 7 | std::cout <<"hello world"< 2 | #include 3 | #include "Cat.h" 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | Cat cat1; 10 | 11 | 12 | cat1.speak(); 13 | cat1.jump(); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /30_header1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | int main(){ 7 | void donothing(); 8 | void donthing(); 9 | return 0; 10 | } 11 | 12 | void donothing(){ 13 | cout << "cpp" < 3 | #include 4 | #include 5 | using namespace std; 6 | int main(){ 7 | cout<< "starting program..."< 2 | using namespace std; 3 | class Animal { 4 | private: 5 | string name; 6 | public: 7 | void setName(string name){this->name;}; 8 | void speak(){ 9 | cout << "my name is " << name << endl; 10 | } 11 | }; 12 | int main(){ 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /20_for.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | 8 | for (int i = 0; i < 10; i++) 9 | { 10 | cout << "hello " << i+1 << endl; // i+1 because i start from 0 11 | 12 | } 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /45_refrencs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void change(int &value) { 4 | value=110; 5 | } 6 | int main(){ 7 | int value=8; 8 | int &value2=value; 9 | value2=10; 10 | cout <<"Value= " << value << endl; 11 | cout <<"Value2= " << value2 << endl; 12 | change(value); 13 | cout <<"Value= " << value << endl; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /33_string_stream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | 9 | string name= "Bob"; 10 | int age=32; 11 | 12 | stringstream ss; 13 | ss << " Name: " << name; 14 | ss << " age: " << age; 15 | 16 | 17 | cout << ss.str() << endl; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /43_char_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int main(){ 5 | char text[]={"hello"}; 6 | 7 | for(int i=0; i 3 | #include 4 | #include 5 | using namespace std; 6 | int main(){ 7 | float f=1.1; 8 | 9 | // forking with if in float 10 | 11 | if (f==1.1) 12 | { 13 | cout << " it is working"; 14 | } 15 | else 16 | cout << " it is not working here"; 17 | // most probably won't work because float value changes in decimal 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /44_reversing_aString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | 5 | char text[]="malyalama "; 6 | int nChars=sizeof(text)-1; 7 | char *pstart= text; 8 | char *pend=text+nChars-1; 9 | while (pstart 2 | using namespace std; 3 | 4 | class Frog{ 5 | private: 6 | string name; 7 | string getname() { 8 | return name ; 9 | } 10 | public: 11 | Frog ( string name ) : name( name ) {} 12 | void info(){ 13 | cout << "My name: " << getname() << endl; 14 | } 15 | }; 16 | 17 | int main(){ 18 | Frog frog("thor"); 19 | frog.info(); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /13_if.cpp: -------------------------------------------------------------------------------- 1 | // program for using of if 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | string pass ="sam" ; 10 | cout << " enter your password " << endl ; 11 | 12 | string input; 13 | cin >> input; 14 | 15 | if ( input == pass ) 16 | { 17 | cout << " password is correct" ; 18 | } 19 | 20 | if (input != pass) 21 | { 22 | cout << "access denied" ; 23 | } 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /24_sixeof_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | 7 | int values[]={1,2,3,4,5,6}; 8 | 9 | cout << sizeof(values) << endl ; // 6*sizeof(int) 10 | cout << sizeof(int) << endl ; // depends on compiler 11 | 12 | for (int i = 0; i < sizeof(values)/sizeof(int); i++) 13 | { 14 | cout << values[ i ] << endl ; 15 | } 16 | 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /07_USER_INPUT.cpp: -------------------------------------------------------------------------------- 1 | // program to take user input 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int main(){ 7 | 8 | cout << " Tell me your 1st name"<< endl; 9 | string name; 10 | // cin takes input 11 | cin >> name ; 12 | cout << " Hello " << name << endl; 13 | 14 | int age; 15 | cout << " What's your age?" << endl; 16 | cin >> age; 17 | cout << " Your age is " << age << endl; 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /17_while_loops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | 8 | /* while (true) 9 | { 10 | cout << "hello" < 2 | using namespace std; 3 | int main(){ 4 | const int elements =5; 5 | string texts[elements]={"one", "two", "three", "four" , "five"}; 6 | string *ptexts=texts; 7 | cout<< *(ptexts+2) << endl; 8 | ptexts+=3; 9 | cout<< *ptexts << endl; 10 | ptexts-=2; 11 | cout<< *ptexts << endl; 12 | 13 | string *pbegin=texts; 14 | string *pend=texts+elements-1; 15 | while (pbegin!=pend+1) 16 | { 17 | cout<< *pbegin << endl; 18 | pbegin++; 19 | } 20 | 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /23_multidimenional_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | string zoo[2][3]={ 7 | {"peacock", "eagle" ,"parrot"}, 8 | {"lion" , "tiger", "elephant"} 9 | 10 | }; 11 | 12 | for (int i = 0; i < 2; i++) 13 | { 14 | for (int j = 0; j < 3; j++) 15 | { 16 | cout << zoo[i][j ]<< " " ; 17 | } 18 | 19 | cout << endl; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /27_functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | void selection(){ 6 | int value ; 7 | const int number=3; 8 | 9 | printf("ENter a value"); 10 | cin >> value; 11 | 12 | switch (value) 13 | { 14 | case 1: 15 | cout <<" starting" << endl; 16 | break; 17 | case 2: 18 | cout <<" processing" << endl; 19 | break; 20 | case number: 21 | cout <<" ending" << endl; 22 | break; 23 | 24 | default: 25 | cout << "unrecognized value"; 26 | 27 | } 28 | 29 | 30 | } 31 | int main() 32 | { 33 | selection(); 34 | 35 | 36 | } -------------------------------------------------------------------------------- /19_do_while.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | // const value can not be chaged later in programming , doing so would give error 7 | const string password = "hello"; 8 | 9 | string input; 10 | 11 | do 12 | { 13 | cout << "enter your password" << endl; 14 | 15 | cin >> input; 16 | 17 | if (input!= password) 18 | { 19 | cout << "access denied " << endl; 20 | } 21 | 22 | } while (input!= password); // loop will go on until we does not enter input equal to password 23 | 24 | 25 | 26 | cout << "password accepted " << endl ; 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /53_inheritance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Animal{ 5 | public: 6 | void speak(){ 7 | cout << "I am a Animal" << endl; 8 | } 9 | }; 10 | class Cat: public Animal{ 11 | public: 12 | void jump(){ 13 | cout << " cat is jumping" << endl; 14 | } 15 | }; 16 | 17 | class Tiger: public Cat{ 18 | public: 19 | void attack(){ 20 | cout << " attack" << endl; 21 | } 22 | }; 23 | 24 | 25 | int main(){ 26 | 27 | Animal a; 28 | a.speak(); 29 | 30 | Cat cat; 31 | cat.jump(); 32 | cat.speak(); 33 | 34 | Tiger tiger; 35 | tiger.attack(); 36 | tiger.jump(); 37 | tiger.speak(); 38 | 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /10_int_type.cpp: -------------------------------------------------------------------------------- 1 | //program for diffrent type of int 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | int main(){ 9 | // normal int value 10 | int normal=23; 11 | cout << normal < 3 | #include 4 | #include 5 | using namespace std; 6 | int main(){ 7 | int vowels=5; 8 | int consonants=21; 9 | float decimal = 3.14; 10 | char letter1='a'; 11 | string sentance =" a string of characters"; 12 | 13 | cout << " number of vowels=" << vowels < 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int i; 8 | 9 | for ( i = 0; i < 10; i++) 10 | 11 | { 12 | 13 | if (i==2) 14 | continue; 15 | 16 | // program will nor run for i=2 as continue statement skips further elements from loop 17 | cout << "i is " << i << endl; 18 | 19 | 20 | if(i==6) 21 | break; 22 | // break throws out program from the loop 23 | cout << "looping ........ " << endl ; 24 | 25 | 26 | } 27 | 28 | cout << "program quitting " << endl ; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /25_sizeofmultidimensionalarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | string zoo[][3]={ 7 | {"peacock", "eagle" ,"parrot"}, 8 | {"lion" , "tiger", "elephant"} 9 | 10 | }; 11 | 12 | cout << sizeof(zoo) < 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | 7 | 8 | void selection(int choice){ 9 | 10 | const int number=3; 11 | 12 | 13 | 14 | switch (choice) 15 | { 16 | case 1: 17 | cout <<" starting" << endl; 18 | break; 19 | case 2: 20 | cout <<" processing" << endl; 21 | break; 22 | case number: 23 | cout <<" ending" << endl; 24 | break; 25 | 26 | default: 27 | cout << "unrecognized value"; 28 | 29 | } 30 | 31 | 32 | }; 33 | int getdata(){ 34 | int value ; 35 | const int number=3; 36 | 37 | printf("ENter a value"); 38 | cin >> value; 39 | return value; 40 | } 41 | int main() 42 | { 43 | int value=getdata(); 44 | selection(value); 45 | 46 | } -------------------------------------------------------------------------------- /14_if_else.cpp: -------------------------------------------------------------------------------- 1 | // programme for basic if else statement 2 | // two digit calculator 3 | 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | int main(){ 9 | int a,b; 10 | // getting two nunbers 11 | cin >> a >> b; 12 | cout << " press + for addition" << endl; 13 | cout << " press - for substraction" << endl; 14 | cout << " press * for multiplication" << endl; 15 | cout << " press / for division" << endl; 16 | 17 | // getting the operation 18 | char op; 19 | cin >> op; 20 | 21 | // final calculation 22 | if (op == '+') 23 | cout << a+b ; 24 | else if(op == '-') 25 | cout << a-b; 26 | else if(op == '*') 27 | cout << a*b; 28 | else 29 | cout << a/b; 30 | 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /21_break_continue_pass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | // const value can not be chaged later in programming , doing so would give error 7 | const string password = "hello"; 8 | 9 | string input; 10 | 11 | do 12 | { 13 | cout << "enter your password" << endl; 14 | 15 | cin >> input; 16 | 17 | if (input== password) 18 | { 19 | break; 20 | } 21 | else 22 | { 23 | cout << "access denied " << endl; 24 | } 25 | 26 | } while (true); // loop will go on until we does not enter input equal to password 27 | 28 | 29 | 30 | cout << "password accepted " << endl ; 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /41_pointers_and_arrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | 5 | // printing string array through normal methods 6 | 7 | string texts[3]={"one", "two", "three"}; 8 | 9 | for (int i = 0; i < sizeof(texts)/sizeof(string); i++) 10 | cout << texts[i] << " " << flush; 11 | cout << endl; 12 | 13 | // printing string array through pointer increment methods 14 | 15 | string *point =&texts[0]; 16 | 17 | for (int i = 0; i < sizeof(texts)/sizeof(string);i++) 18 | cout << *(point +i ) << " " << flush; 19 | cout << endl; 20 | 21 | // printing string array through pointer compare methods 22 | 23 | string *pbeg= &texts[0]; 24 | string *pend= &texts[2]; 25 | while (true){ 26 | cout << *(pbeg )<< " " << flush; 27 | if (*pbeg ==*pend) 28 | break; 29 | *pbeg++; 30 | } 31 | 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /39_pointers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | void manipulate(double *dvalue){ 5 | cout << "2. value of dvalue in manipulate is " << *dvalue << endl; 6 | *dvalue = 10.0; 7 | cout << "3. value of dvalue in manipulate is " << *dvalue << endl; 8 | } 9 | int main(){ 10 | int nvalue = 8; 11 | int *pnvalue = &nvalue; 12 | 13 | cout << " value of nvalue is " << nvalue << endl; 14 | cout << " value of pnvalue is " << pnvalue << endl; 15 | cout << " value of *pnvalue is " << *pnvalue << endl; 16 | 17 | cout << "=================================================" << endl; 18 | 19 | double dvalue = 123.4; 20 | cout << "1. value of dvalue is " << dvalue << endl; 21 | manipulate(&dvalue); 22 | cout << "4. value of dvalue is " << dvalue << endl; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /48_new_operator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Animal 6 | { 7 | private: 8 | string name; 9 | public: 10 | Animal(/* args */); 11 | ~Animal(); 12 | Animal(const Animal & other) : name(other.name){ 13 | cout << " animal by coopy" << endl; 14 | } 15 | void setName(string name){ this->name = name;}; 16 | void speak() const { cout << "My name is " << name << endl;} 17 | }; 18 | 19 | Animal::Animal(/* args */) 20 | { 21 | cout<<"Animal created" << endl; 22 | } 23 | 24 | Animal::~Animal() 25 | { 26 | cout<<"Animal dead" << endl; 27 | 28 | } 29 | 30 | 31 | int main(){ 32 | 33 | Animal *animal1 = new Animal(); 34 | animal1->setName("cheems"); 35 | 36 | animal1->speak(); 37 | delete animal1; 38 | cout << sizeof(animal1); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /26_switch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | int value ; 7 | const int number=3; 8 | 9 | printf("ENter a value"); 10 | cin >> value; 11 | 12 | switch (value) 13 | { 14 | case 1: 15 | cout <<" I am in case 1" << endl; 16 | break; 17 | case 2: 18 | cout <<" I am in case 2" << endl; 19 | break; 20 | case number: 21 | cout <<" I am in case 3" << endl; 22 | break; 23 | case 4: 24 | cout <<" I am in case 4" << endl; 25 | break; 26 | case 5: 27 | cout <<" I am in case 5" << endl; 28 | break; 29 | case 6: 30 | cout <<" I am in case 6" << endl; 31 | break; 32 | default: 33 | cout << "unrecognized value"; 34 | 35 | } 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /28_return.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int selection(){ 6 | int value ; 7 | const int number=3; 8 | 9 | printf("ENter a value"); 10 | cin >> value; 11 | 12 | return value; 13 | } 14 | int main(){ 15 | int value=selection(); 16 | switch (value) 17 | { 18 | case 1: 19 | cout <<" I am in case 1" << endl; 20 | break; 21 | case 2: 22 | cout <<" I am in case 2" << endl; 23 | break; 24 | case 3: 25 | cout <<" I am in case 3" << endl; 26 | break; 27 | case 4: 28 | cout <<" I am in case 4" << endl; 29 | break; 30 | case 5: 31 | cout <<" I am in case 5" << endl; 32 | break; 33 | case 6: 34 | cout <<" I am in case 6" << endl; 35 | break; 36 | default: 37 | cout << "unrecognized value"; 38 | 39 | } 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /11_float_type.cpp: -------------------------------------------------------------------------------- 1 | // program for diffrent type of float 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | int main(){ 9 | // normal float value 10 | float normal=23.123456789; 11 | cout << normal < 2 | 3 | using namespace std; 4 | void show1(const int n, string texts[]){ 5 | cout << "size of texts in show1 " << sizeof(texts) << endl; 6 | 7 | for (int i = 0; i < n; i++){ 8 | cout << texts[i] << endl; 9 | } 10 | } 11 | 12 | void show2(const int n, string *texts){ 13 | cout << "size of texts in show2 " << sizeof(texts) << endl; 14 | 15 | for (int i = 0; i < n; i++){ 16 | cout << texts[i] << endl; 17 | } 18 | } 19 | void show3(string (&texts)[3]){ 20 | cout << "size of texts in show3 " << sizeof(texts) << endl; 21 | 22 | for (int i = 0; i < sizeof(texts) / sizeof(string); i++){ 23 | cout << texts[i] << endl; 24 | } 25 | } 26 | 27 | int main(){ 28 | 29 | string texts[] = {"one", "two", "three"}; 30 | cout << "size of texts in main " << sizeof(texts) << endl; 31 | show1(3, texts); 32 | show2(3, texts); 33 | show3(texts); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /50_allocating_memories.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Animal 6 | { 7 | private: 8 | string name; 9 | public: 10 | Animal(/* args */); 11 | ~Animal(); 12 | Animal(const Animal & other) : name(other.name){ 13 | cout << " animal by coopy" << endl; 14 | } 15 | void setName(string name){ this->name = name;}; 16 | void speak() const { cout << "My name is " << name << endl;} 17 | }; 18 | 19 | Animal::Animal(/* args */) 20 | { 21 | cout<<"Animal created" << endl; 22 | } 23 | 24 | Animal::~Animal() 25 | { 26 | cout<<"Animal dead" << endl; 27 | } 28 | 29 | Animal createAnimal(){ 30 | Animal a; 31 | return a; 32 | a.setName("doggo"); 33 | } 34 | int main(){ 35 | 36 | Animal *animal = new Animal[10]; 37 | animal[5].setName("cheems"); 38 | animal[5].speak(); 39 | delete [] animal; 40 | 41 | Animal dog=createAnimal(); 42 | dog.speak(); 43 | cout << sizeof(dog) << endl; 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /49_createClassByFuncTion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Animal 6 | { 7 | private: 8 | string name; 9 | public: 10 | Animal(/* args */); 11 | ~Animal(); 12 | Animal(const Animal & other) : name(other.name){ 13 | cout << " animal by coopy" << endl; 14 | } 15 | void setName(string name){ this->name = name;}; 16 | void speak() const { cout << "My name is " << name << endl;} 17 | }; 18 | 19 | Animal::Animal(/* args */) 20 | { 21 | cout<<"Animal created" << endl; 22 | } 23 | 24 | Animal::~Animal() 25 | { 26 | cout<<"Animal dead" << endl; 27 | 28 | } 29 | 30 | Animal createAnimal(){ 31 | Animal a; 32 | a.setName("doggo"); 33 | return a; 34 | } 35 | int main(){ 36 | 37 | Animal *animal1 = new Animal(); 38 | animal1->setName("cheems"); 39 | 40 | animal1->speak(); 41 | delete animal1; 42 | Animal dog=createAnimal(); 43 | dog.speak(); 44 | cout << sizeof(dog) << endl; 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /22_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | int value[3]; 7 | // declaring and printing every element one by one 8 | value[0]=1; 9 | value[1]=2; 10 | value[2]=3; 11 | 12 | cout << "array of ints" << endl ; 13 | 14 | cout << value[00] << endl ; 15 | cout << value[01] << endl ; 16 | cout << value[02] << endl ; 17 | 18 | /// declaring and printing all elements in one go 19 | 20 | cout << "array of ints" << endl ; 21 | double nums[4] ={ 2.2 ,4.4,6.6}; 22 | 23 | for (int i = 0; i < 4; i++) /// here 4th element is not initilized 24 | { 25 | cout << nums[i] << endl ; 26 | } 27 | 28 | cout << "array of string" << endl ; 29 | 30 | string text[]={ "apple" , "banana" , "orange"} ; 31 | 32 | for (int i = 0; i < 4; i++) /// here 4th element is not initilized 33 | { 34 | cout << text[i] << endl ; 35 | } 36 | 37 | 38 | 39 | 40 | 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /40_arthimatic.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int main(){ 5 | /* 6 | * + 7 | * - 8 | * * 9 | * / 10 | * % 11 | * += 12 | * -= 13 | * *= 14 | * /= 15 | * %= 16 | * ++ 17 | * -- 18 | */ 19 | int a = 50, b = 20; 20 | cout << "Value of a and b is " << a << " & " << b << endl; 21 | cout << "Value of a+b is " << a + b << endl; 22 | cout << "Value of a-b is " << a - b << endl; 23 | cout << "Value of a*b is " << a * b << endl; 24 | cout << "Value of a/b is " << a / b << endl; 25 | cout << "Value of a%b is " << a % b << endl; 26 | cout << "Value of ++a is " << ++a << endl; 27 | cout << "Value of --a is " << --a << endl; 28 | cout << "Value of a++ is " << a++ << endl; 29 | cout << "Value of a-- is " << a-- << endl; 30 | a += b; 31 | cout << "Value of a+=b is " << a << endl; 32 | a -= b; 33 | cout << "Value of a-= is " << a << endl; 34 | a *= b; 35 | cout << "Value of a*=b is " << a << endl; 36 | a /= b; 37 | cout << "Value of a/=b is " << a << endl; 38 | a %= b; 39 | cout << "Value of a%=b is " << a << endl; 40 | return 0; 41 | } -------------------------------------------------------------------------------- /16_conditions.cpp: -------------------------------------------------------------------------------- 1 | // complex conditions in cpp 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | /* 8 | * == equality test 9 | * != not equals 10 | * < less than 11 | * > greater than 12 | * <= less than or equal to 13 | * >= greater than or equal to 14 | * && and operator 15 | * || or operator 16 | */ 17 | 18 | 19 | int main(){ 20 | int value1=7, value2= 4; 21 | 22 | // condition 1 checking equality operator 23 | if (value1 == 7 ) 24 | { 25 | cout << " Condition 1 : true " << endl ; // value1 is 7 which is equal to 7 , so this statement will be executed. 26 | } 27 | else 28 | { 29 | cout << " Condition 1 : false " << endl ; // the if statement is true so else satement will not execute. 30 | } 31 | 32 | // condition 2 checking not equal operator 33 | if (value1 != 8 ) // condition 2 34 | { 35 | cout << " Condition 2 : true " << endl ; // value1 is 7 which is not equal to 8 , so this statement will be executed. 36 | } 37 | else 38 | { 39 | cout << " Condition 2 : false " << endl ; // the if statement is true so else satement will not execute. 40 | } 41 | 42 | //condition 3 checks less than operator 43 | if (value1 < 8 ) // condition 3 44 | { 45 | cout << " Condition 3 : true " << endl ; // value1 is 7 which is less than 8 , so this statement will be executed. 46 | } 47 | else 48 | { 49 | cout << " Condition 3 : false " << endl ; // the if statement is true so else satement will not execute. 50 | } 51 | 52 | // condition 4 checks greter than operator 53 | if (value1 > 8 ) // condition 1 54 | { 55 | cout << " Condition 4 : true " << endl ; // value1 is 7 which is not greater than 8 , so this statement will not be executed. 56 | } 57 | else 58 | { 59 | cout << " Condition 4 : false " << endl ; // the if statement is true so else satement will execute. 60 | } 61 | 62 | 63 | // condition 5 checks less than or equal to 64 | if (value1 <= value2 ) // condition 5 65 | { 66 | cout << " Condition 5 : true " << endl ; // value1 is 7 which is not less than or equal to value 2 which is 4 , so this statement will not be executed. 67 | } 68 | else 69 | { 70 | cout << " Condition 5 : false " << endl ; // the if statement is false so else satement will execute. 71 | } 72 | 73 | 74 | //condition 6 checks greater than or equal to 75 | if (value1 >= value2 ) // condition 6 76 | { 77 | cout << " Condition 6 : true " << endl ; // value1 is 7 which is greater than 4 , so this statement will be executed. 78 | } 79 | else 80 | { 81 | cout << " Condition 6 : false " << endl ; // the if statement is true so else satement will not be execued 82 | } 83 | 84 | 85 | //condition 7 checks and operator 86 | if ( value1 >= value2 && value1 ==7 ) // condition 6 87 | { 88 | cout << " Condition 7 : true " << endl ; // value1 is 7 which is greater than 4 and at the same time value1 is equal to 7 , so this statement will be executed. 89 | } 90 | else 91 | { 92 | cout << " Condition 7 : false " << endl ; // the if statement is true so else satement will not be execued 93 | } 94 | 95 | 96 | //condition 8 checks or operator 97 | if (value1 <= value2 || value1 > 0 ) // condition 6 98 | { 99 | cout << " Condition 8 : true " << endl ; // value1 is 7 which is not lesser than than value2 which is 4 but value1 is greater than 0 , so this statement will be executed. 100 | } 101 | else 102 | { 103 | cout << " Condition 8 : false " << endl ; // the if statement is true so else satement will not be execued 104 | } 105 | 106 | return 0; 107 | } --------------------------------------------------------------------------------