├── .gitattributes ├── All ASCII values └── All ASCII values.cpp ├── Cartesian and Polar conversion ├── Assignment3.pdf └── Cartesian and Polar conversion.cpp ├── Check if String is palindrome └── Check if String is palindrome .cpp ├── Class of point └── Class of point .cpp ├── Find taylor series ├── Assignment2.pdf └── Find taylor series.cpp ├── Geo-coordinates(Longitude and Latitude) expressed in deg min and sec ├── Assignment3.pdf └── Geo-coordinates(Longitude and Latitude) expressed in deg min and sec.cpp ├── README.md ├── Store data in RAM by pointer ├── Store data in RAM by pointer.cpp └── Store data in RAM by pointer.exe ├── Tells letters are lower or upercase case └── Tells letters are lower or upercase case .cpp ├── assigning array to an integer └── assigning array to an integer.cpp ├── cocatinate 2 strings └── cocatinate 2 strings.cpp ├── convert charracter into number └── convert charracter into number .cpp ├── day and time accurate difference ├── Assignment3.pdf └── day and time accurate difference.cpp ├── delet any element from array └── delet any element from array.cpp ├── different kinds of triangles ├── Assignment2.pdf └── different kinds of triangles.cpp ├── draw a line without graphics ├── Assignment2.pdf └── draw a line without graphics.cpp ├── enter data in file └── enter data in file.cpp ├── grade sheet of students ├── Assignment4.pdf └── grade sheet of students.cpp ├── gread sheet of students ├── Assignment4.pdf └── gread sheet of students.cpp ├── input from file and store it in array └── input from file and store it in array.cpp ├── input from file check is number and perform operation └── input from file check is number and perform operation .cpp ├── input from file store it in array and sort it └── input from file store it in array and sort it.cpp ├── input from file, perform operationand show ERROR in case of wrong input └── input from file, perform operationand show ERROR in case of wrong input.cpp ├── input from user and check number is binary or not ├── Assignment2.pdf └── input from user and check number is binary or not.cpp ├── input total student ,total marks,and obtain marks and display its graph ├── Assignment2.pdf └── input total student ,total marks,and obtain marks and display its graph.cpp ├── left down triangle with loop └── left down triangle with loop.cpp ├── left-upward-triangle └── left-upward-triangle .cpp ├── ll gram inside a rectangle └── ll gram inside a rectangle.cpp ├── numerator & denominator in a reduces fraction ├── Assignment3.pdf └── numerator & denominator in a reduces fraction.cpp ├── queue of number by class └── queue of number by class.cpp ├── read data from file and opertion on it └── read data from file and opertion on it.cpp ├── rectangle by Class └── rectangle by Class.cpp ├── reverse arry by single loop └── reverse arry by single loop.cpp ├── reverse of array └── reverse of array.cpp ├── reverse string └── reverse string.cpp ├── right down triangle with loop └── right down triangle with loop.cpp ├── right upward triangle with loop └── right upward triangle with loop.cpp ├── right+left up_triangle with loop └── right+left up_triangle with loop.cpp ├── rigt+left down_triangle with loop └── rigt+left down_triangle with loop.cpp ├── space invaders console based c++ projects ├── READ ME.txt ├── mygraphics.h └── space invaders console based c++ projects.cpp ├── stack of number └── stack of numbers.cpp ├── sum by type casting └── sum by type casting.cpp └── write in file └── write in file.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /All ASCII values/All ASCII values.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | 6 | for(int i = 0; i <= 255; i++) { 7 | printf("\nASCII of %d : %c",i,i); 8 | } 9 | 10 | getch(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Cartesian and Polar conversion/Assignment3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fazeelkhalid/Cpp-Programming-practice-problems-and-solutions/84d203c99ed4882dbcf6216f4ecc1198f0c9a240/Cartesian and Polar conversion/Assignment3.pdf -------------------------------------------------------------------------------- /Cartesian and Polar conversion/Cartesian and Polar conversion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void car_to_pol(float x,float y,float &R,float &Q) { 7 | 8 | R = sqrt(x*x + y*y); //R is the sum of x component and y component 9 | Q = atan2(y, x) * (180 / 3.141592) ; //Q is the angle 10 | 11 | } 12 | 13 | void pol_to_car(float R, float Q, float &x, float &y) { 14 | Q *= 3.1415 / 180; 15 | x = R * cos(Q); //R is x component 16 | y = R * sin(Q); // Q is y component 17 | } 18 | 19 | int main() { 20 | 21 | int opetion; 22 | 23 | cout<<"********** PRESS **********\n1 for carrtesian to polar\n2 for polar to carrtesion :"; 24 | cin>>opetion; 25 | if(opetion == 1) { 26 | float x; 27 | float y; 28 | float R; 29 | float Q; 30 | 31 | cout<<"input x component :"; 32 | cin>>x; //x component 33 | cout<<"input y component :"; 34 | cin>>y; //y component 35 | 36 | car_to_pol(x,y,R,Q); 37 | 38 | cout<<"carrtesian coordintes : "<<"("<>R; //sum of x component and y component 50 | cout<<"input angle :"; 51 | cin>>Q; //angle 52 | 53 | pol_to_car(R,Q,x,y); 54 | 55 | cout<<"polar coordintes : "<<"("< 2 | 3 | int main() { 4 | int n = 5; 5 | int number[n]; 6 | int index = 0; 7 | 8 | 9 | for(int index = 0; index < n; index++) { 10 | printf("Enter number : "); 11 | scanf("%d",&number[index]); 12 | } 13 | 14 | for(; index < n/2;) { 15 | if(number[index] == number [n-1-index]) 16 | index++; 17 | else 18 | break; 19 | } 20 | 21 | if(index == n/2 ) 22 | printf("The array that you enter is a palindrome"); 23 | else 24 | printf("The array that you enter is \"not\" a palindrome"); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Class of point/Class of point .cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class point { 6 | 7 | private: 8 | float Y; 9 | float X; 10 | 11 | public: 12 | point(float a, float b) { 13 | this->X = a; 14 | this->Y = b; 15 | } 16 | 17 | void print(){ 18 | cout<< "(" <X << "," << this->Y << ")"; 19 | } 20 | 21 | void setX(float c) { 22 | this->X = c; 23 | } 24 | 25 | void setY(float c) { 26 | this->Y = c; 27 | } 28 | 29 | float getY(){ 30 | return this->Y; 31 | } 32 | float getX(){ 33 | return this->X; 34 | } 35 | 36 | }; 37 | 38 | int main() { 39 | 40 | point p(400,30); 41 | p.print(); 42 | 43 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int x; 8 | int terms; 9 | float numerator = 0; 10 | float denominator = 0; 11 | float answer = 0; 12 | 13 | cout<<"enter the value of x :"; 14 | cin>>x; 15 | cout<<"enter number of terms :"; 16 | cin>>terms; 17 | 18 | for(int i = 0; i < terms; i++) { 19 | numerator *= x; 20 | denominator *= i; 21 | 22 | numerator = !numerator ? 1 : numerator; 23 | denominator = !denominator ? 1 : denominator; 24 | answer += numerator / denominator; 25 | 26 | if(x == 0) 27 | break; 28 | } 29 | cout< 2 | 3 | using namespace std; 4 | 5 | float geoToDecimal (float d1, float m1,float s1,float d2,float m2, float s2,float &decimalLatitude) { 6 | 7 | if(d1 < 0) { 8 | decimalLatitude = d1 - (m1/60) - (s1/3600); 9 | } 10 | else{ 11 | decimalLatitude = d1 + (m1/60) + (s1/3600); 12 | } 13 | 14 | if(d2 < 0) { 15 | return d2 - (m2/60) -(s2/3600); 16 | } 17 | else 18 | return d2 + (m2/60) + (s2/3600); 19 | 20 | } 21 | 22 | int main() { 23 | 24 | float degree1; 25 | float min1; 26 | float sec1; 27 | float degree2; 28 | float min2; 29 | float sec2; 30 | float decimalLatitude; 31 | float decimalLongitude; 32 | char c; 33 | 34 | cout<<"******************** Format DD*MM'SS\" ********************\n"; 35 | cout<<"Enter Degrees Minutes Seconds latitude : "; 36 | cin>>degree1>>c>>min1>>c>>sec1>>c; 37 | cout<<"Enter Degrees Minutes Seconds longitude : "; 38 | cin>>degree2>>c>>min2>>c>>sec2>>c; 39 | 40 | decimalLongitude = geoToDecimal(degree1, min1, sec1, degree2, min2, sec2, decimalLatitude); 41 | 42 | cout<<"Decimal latitude : "<

Problem - 1

16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |

All Ascii Value

31 | Print all Ascii value with there symbols on the console. 32 | 33 | 34 | -------------------------------------------------------------------------------- /Store data in RAM by pointer/Store data in RAM by pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Node { 6 | public: 7 | Node *next; 8 | int number; 9 | }; 10 | 11 | class List { 12 | private: 13 | Node *head; 14 | 15 | public: 16 | List() { 17 | this->head = NULL; 18 | } 19 | 20 | List(const List &obj) { 21 | this->head = NULL; 22 | 23 | Node *temp1 = obj.head; 24 | Node *temp2 = this->head; 25 | 26 | while(temp1 != NULL) { 27 | Node *n = new Node(); 28 | n->number = temp1->number; 29 | n->next = NULL; 30 | 31 | if(this->head == NULL) 32 | this->head = n; 33 | else { 34 | temp2->next = n; 35 | temp2 = temp2->next; 36 | } 37 | 38 | temp1 = temp1->next; 39 | } 40 | } 41 | 42 | void add(int X) { 43 | Node *n = new Node(); 44 | n->number = X; 45 | n->next = NULL; 46 | 47 | if(this->isEmpty()) { 48 | this->head = n; 49 | return; 50 | } 51 | 52 | Node *temp; 53 | temp = this->head ; 54 | while(temp->next != NULL) { 55 | temp = temp->next; 56 | } 57 | temp->next = n; 58 | return; 59 | } 60 | 61 | void print() { 62 | Node *temp; 63 | temp = this->head; 64 | 65 | while(temp != NULL) { 66 | cout<number<<", "; 67 | temp = temp->next; 68 | } 69 | cout<head; 76 | Node *a; 77 | 78 | if(head->number == X) { 79 | head = head->next; 80 | delete temp; 81 | return ; 82 | } 83 | 84 | while(temp->next != NULL) { 85 | 86 | if(temp->next->number == X){ 87 | a = temp->next; 88 | temp->next = temp->next->next; 89 | a->next = NULL; 90 | delete a; 91 | return; 92 | } 93 | temp = temp->next; 94 | } 95 | } 96 | 97 | bool search(int X) { 98 | Node *temp = this->head; 99 | 100 | while(temp !=NULL) { 101 | 102 | if(temp->number == X) { 103 | return true; 104 | } 105 | 106 | temp = temp->next; 107 | } 108 | return false; 109 | } 110 | 111 | bool isEmpty() { 112 | if(head == NULL) { 113 | return true; 114 | } 115 | else 116 | return false; 117 | } 118 | 119 | void replace(int X,int Y) { 120 | Node *temp = this->head; 121 | 122 | while(temp !=NULL) { 123 | if(temp->number == X) { 124 | temp->number = Y; 125 | } 126 | temp = temp->next; 127 | } 128 | return; 129 | } 130 | 131 | void allRemove() { 132 | while(head->next != NULL) { 133 | Node *n = head ; 134 | head = head->next; 135 | n->next = NULL; 136 | delete n; 137 | } 138 | delete head; 139 | head = NULL; 140 | } 141 | }; 142 | 143 | int main() { 144 | 145 | List l; 146 | l.add(5); 147 | l.add(10); 148 | l.add(15); 149 | l.add(99); 150 | 151 | l.print(); 152 | 153 | l.remove(15); 154 | 155 | l.print(); 156 | 157 | cout< 2 | #include 3 | 4 | int main() { 5 | int num; 6 | 7 | printf("Enter any letter that you want to test : "); 8 | scanf("%c",&num); 9 | 10 | if(num>='A' && num<='Z') 11 | printf("you entered an upper case letter that is %c",num); 12 | else if (num>='a' && num<'=z') 13 | printf("you entered an lower case letter that is %c",num); 14 | else 15 | printf("you entered a number, special symbol or blank space"); 16 | 17 | return 0; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /assigning array to an integer/assigning array to an integer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char a[10]; 6 | int b; 7 | 8 | printf("Enter any number that you want to assign to the integer : "); 9 | scanf("%s", &a); 10 | 11 | b=a[10]; 12 | printf("%d",b); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /cocatinate 2 strings/cocatinate 2 strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | char first_name[30]; 7 | char second_name[30]; 8 | char full_name[60]; 9 | int size = 0; 10 | 11 | cout<<"Enter first name : "; 12 | cin>>first_name; 13 | 14 | cout<<"Enter second name : "; 15 | cin>>second_name; 16 | 17 | for(int i = 0; first_name[i] != '\0'; i++) 18 | size++; 19 | 20 | for(int i = 0; i < size; i++) { 21 | full_name[i] = first_name[i]; 22 | } 23 | 24 | for(int i = size; i < 60; i++) { 25 | full_name[i] = second_name[i-size]; 26 | } 27 | 28 | cout< 2 | #include 3 | 4 | int main() { 5 | char ch; 6 | 7 | printf("Enter any number that you eant to convert into number : "); 8 | scanf("%c", &ch); 9 | 10 | if(ch>='0' && ch<='9') 11 | printf("integer value of charracter %c = %d ", ch, (ch-48)); 12 | else 13 | printf("please just enter number"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /day and time accurate difference/Assignment3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fazeelkhalid/Cpp-Programming-practice-problems-and-solutions/84d203c99ed4882dbcf6216f4ecc1198f0c9a240/day and time accurate difference/Assignment3.pdf -------------------------------------------------------------------------------- /day and time accurate difference/day and time accurate difference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int dayinMonth(int md,int y1) { 6 | int daymonth = 0; 7 | for(md; md > 0; md-- ) { 8 | 9 | if(md == 1 || md == 3|| md == 5|| md == 7|| md == 8 ||md == 10||md == 12) { 10 | daymonth += 31; 11 | } 12 | else if(md == 4 || md == 6 || md == 9|| md == 11){ 13 | daymonth += 30; 14 | } 15 | 16 | else if(md == 2 && y1 % 4 == 0) { 17 | daymonth += 29; 18 | } 19 | else 20 | daymonth += 28; 21 | 22 | 23 | } 24 | return daymonth; 25 | } 26 | int dayinYear(int yd,int y2,int y1) { 27 | int dayinYear = 0; 28 | for(int i = y2; i < y1; i++) { 29 | if(i % 4 == 0) { 30 | dayinYear +=366; 31 | } 32 | else 33 | dayinYear +=365; 34 | } 35 | 36 | return dayinYear; 37 | } 38 | 39 | int datediff(int y1, int m1,int d1, int y2, int m2, int d2, int &yd, int &md, int &dd ) { 40 | 41 | if(d1 - d2 < 0) { 42 | 43 | if(m1 == 1 || m1 == 3|| m1 == 5|| m1 == 7|| m1 == 8 ||md == 10||m1 == 12) { 44 | d1 += 31; 45 | m1 -= 1; 46 | } 47 | else if(m1 == 4 || m1 == 6 || m1 == 9|| m1 == 11){ 48 | d1 +=30; 49 | m1 -= 1; 50 | } 51 | 52 | else if(m1 == 2 && y1 % 4 == 0) { 53 | d1 += 29; 54 | m1 -= 1; 55 | } 56 | else { 57 | d1 += 28; 58 | m1 -= 1; 59 | } 60 | } 61 | 62 | if(m1 - m2 < 0) { 63 | m1 += 12; 64 | y1 -= 1; 65 | } 66 | yd = y1 - y2; 67 | dd = d1- d2; 68 | md = m1 - m2; 69 | int result; 70 | 71 | result = dayinYear(yd,y2,y1) + dayinMonth(md,y1) + dd ; 72 | return result; 73 | } 74 | 75 | int timediff(int h1,int m1, int s1, int h2, int m2, int s2 ,int &hd, int &md, int &sd) { 76 | int result; 77 | 78 | if(s1 - s2 < 0) { 79 | s1 += 60; 80 | m1 -= 1; 81 | } 82 | if(m1 - m2 < 0) { 83 | m1 += 60; 84 | h1 -= 1; 85 | } 86 | hd = h1 - h2; 87 | md = m1 - m2; 88 | sd = s1 - s2; 89 | result = hd*3600 + md * 60 + sd; 90 | return result; 91 | } 92 | 93 | int main() { 94 | 95 | char operation; 96 | 97 | cout<<"Enter T for time difference and D for date difference :"; 98 | cin>>operation; 99 | 100 | if(operation == 'D' || operation == 'd') { 101 | 102 | int year1; 103 | int year2; 104 | int month1; 105 | int month2; 106 | int day1; 107 | int day2; 108 | char c; 109 | int result; 110 | int yd; 111 | int md; 112 | int dd; 113 | 114 | cout<<"****************** firstly input larger date ******************\n"; 115 | cout<<"******************* Date format: DD/MM/YYYY *******************\n"; 116 | cout<<"Enter first date : "; 117 | cin>>day1>>c>>month1>>c>>year1; 118 | if((day1 >= 0 && day1 <= 31) && (month1 >= 1 && month1 <= 12)) { 119 | cout<<"Enter second date : "; 120 | cin>>day2>>c>>month2>>c>>year2; 121 | 122 | if((day2 >= 0 && day2 <= 31) && (month2 >= 0 && month2 <= 12)) { 123 | result = datediff(year1, month1, day1, year2, month2, day2, yd, md, dd); 124 | cout<<"Total difference of date :"<>hour1>>c>>min1>>c>>sec1; 155 | 156 | if((hour1 >= 0 && hour1 <= 24) && (min1 >= 0 && min1 <= 60) && (sec1 >= 0 && sec1 <= 60)) { 157 | 158 | cout<<"Enter second time :"; 159 | cin>>hour2>>c>>min2>>c>>sec2; 160 | 161 | if((hour2 >= 0 && hour2 <= 24) && (min2 >= 0 && min2 <= 60) && (sec2 >= 0 && sec2 <= 60)) { 162 | 163 | result = timediff(hour1, min1, sec1, hour2, min2, sec2, hd, md, sd); 164 | cout<<"total time difference in second:"< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int rows; 7 | int space; 8 | int temp; 9 | int coloum = 1; 10 | 11 | cout<<"Please enter number of rows :"; 12 | cin>>rows; 13 | temp = rows; 14 | 15 | for(int i = 0; i < rows; i++){ 16 | for(int j = 0; j <= i; j++){ 17 | cout<<"*"; 18 | } 19 | cout< i; k--) 27 | cout<<" "; 28 | 29 | for(int j = 0;j <= i; j++){ 30 | cout<<"*"; 31 | } 32 | cout< i; j--){ 38 | cout<<"*"; 39 | } 40 | cout< 0; i--) { 45 | for(int j = 0; j < i; j++) { 46 | cout<<"*"; 47 | } 48 | cout< 0) { 65 | cout<<" "; 66 | space--; 67 | } 68 | temp--; 69 | 70 | for(int k = 0; k < coloum ; k++) { 71 | cout<<"*"; 72 | } 73 | 74 | coloum = coloum + 2; 75 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int slope; 8 | int yIntercept; 9 | int y; 10 | 11 | cout<<"Enter slope :"; 12 | cin>>slope; 13 | cout<<"Enter Y intercept :"; 14 | cin>>yIntercept; 15 | if(slope >= 0 && yIntercept >= 0) { 16 | 17 | for(int x = 5; x > 0; x--) { 18 | y = slope * x + yIntercept; 19 | 20 | for(int i = 0; i < y; i++) 21 | cout<<" "; 22 | cout<<"*"< 2 | 3 | int main() 4 | { 5 | 6 | FILE *fp; 7 | char sentence[] = "FAZEEL KHALID"; 8 | 9 | fp = fopen("write.txt", "w"); 10 | fprintf("%s", sentence); 11 | fclose(fp); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /grade sheet of students/Assignment4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fazeelkhalid/Cpp-Programming-practice-problems-and-solutions/84d203c99ed4882dbcf6216f4ecc1198f0c9a240/grade sheet of students/Assignment4.pdf -------------------------------------------------------------------------------- /grade sheet of students/grade sheet of students.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void computeWeightAge( float (&totalIndvidualMarks)[50], float cMarks[], float eMarks[], float pMarks[], float sMarks[], float dMarks[], int size,float &Marks) { 7 | Marks = 0; 8 | float weigthAge[5]; 9 | int totalMarks[5]; 10 | 11 | for(int i = 0; i < 85; i++) { 12 | cout<<"*"; 13 | } 14 | cout<>totalMarks[i]; 19 | } 20 | 21 | for(int i = 0; i < 85; i++) { 22 | cout<<"*"; 23 | } 24 | cout<> weigthAge[i]; 29 | Marks = Marks + weigthAge[i]; 30 | } 31 | for(int i = 0; i < 5; i++ ) { //total marks of students 32 | cMarks[i] = cMarks[i]/totalMarks[0]*weigthAge[0]; 33 | eMarks[i] = (eMarks[i]/totalMarks[1]*weigthAge[1]); 34 | pMarks[i] = (pMarks[i]/totalMarks[2]*weigthAge[2]); 35 | sMarks[i] =(sMarks[i]/totalMarks[3]*weigthAge[3]); 36 | dMarks[i] = (dMarks[i]/totalMarks[4]*weigthAge[4]); 37 | totalIndvidualMarks[i] =cMarks[i] + eMarks[i] + pMarks[i] + sMarks[i] + dMarks[i]; 38 | } 39 | } 40 | 41 | void swapNumber(float &firstNumber, float &secondNumber){ 42 | 43 | float temp; 44 | 45 | temp = firstNumber; 46 | firstNumber = secondNumber; 47 | secondNumber = temp; 48 | 49 | } 50 | void swapNumber(int &firstNumber, int &secondNumber){ 51 | 52 | int temp; 53 | 54 | temp = firstNumber; 55 | firstNumber = secondNumber; 56 | secondNumber = temp; 57 | 58 | } 59 | 60 | void selectionSort( int (&rNumber)[50],float (&totalIndvidualMarks)[50], float (&cMarks)[50], float (&eMarks)[50], float (&pMarks)[50], float (&sMarks)[50], float (&dMarks)[50], int size, char choose) { 61 | 62 | if(choose == 'A' || choose =='a') { // for Assending order 63 | 64 | for(int i = 0; i < size - 1; i++) { 65 | int small = rNumber[i]; 66 | int Sindex; 67 | bool found = false; 68 | for(int j = i+1; j < size; j++) { 69 | if(small > rNumber[j] ) { 70 | small = rNumber[j]; 71 | Sindex = j; 72 | found = true; 73 | } 74 | } 75 | if(found){ 76 | swapNumber(totalIndvidualMarks[i],totalIndvidualMarks[Sindex]); 77 | swapNumber(eMarks[i],eMarks[Sindex]); 78 | swapNumber(pMarks[i],pMarks[Sindex]); 79 | swapNumber(sMarks[i],sMarks[Sindex]); 80 | swapNumber(dMarks[i],dMarks[Sindex]); 81 | swapNumber(rNumber[i],rNumber[Sindex]); 82 | } 83 | } 84 | } 85 | 86 | if(choose == 'D' || choose =='d') { // for Assending order 87 | 88 | for(int i = 0; i < size - 1; i++) { 89 | int small = rNumber[i]; 90 | int Sindex; 91 | bool found = false; 92 | for(int j = i+1; j < size; j++) { 93 | if(small < rNumber[j] ) { 94 | small = rNumber[j]; 95 | Sindex = j; 96 | found = true; 97 | } 98 | } 99 | if(found){ 100 | swapNumber(totalIndvidualMarks[i],totalIndvidualMarks[Sindex]); 101 | swapNumber(eMarks[i],eMarks[Sindex]); 102 | swapNumber(pMarks[i],pMarks[Sindex]); 103 | swapNumber(sMarks[i],sMarks[Sindex]); 104 | swapNumber(dMarks[i],dMarks[Sindex]); 105 | swapNumber(rNumber[i],rNumber[Sindex]); 106 | } 107 | } 108 | } 109 | } 110 | 111 | void search(int (&rNumber)[50],float (&totalIndvidualMarks)[50],float (&cMarks)[50],float (&eMarks)[50],float (&pMarks)[50],float (&sMarks)[50],float (&dMarks)[50],int size,char choose,float Marks) { 112 | 113 | int studentSearch; 114 | int end; 115 | int middle; 116 | 117 | bool present = false; 118 | end = size - 1; // 0 119 | 120 | selectionSort(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose); 121 | 122 | cout<<"\nEnter roll number for searching : "; 123 | cin>>studentSearch; 124 | 125 | for(int starting = 0; starting <= end;) { 126 | middle = (starting+end) / 2; 127 | if(studentSearch == rNumber[middle]) { // for list of student 128 | cout<<"\nStudent Roll Number : "< rNumber[middle]){ 140 | starting = middle+1; 141 | } 142 | else 143 | end = middle-1; 144 | } 145 | if(!present) { 146 | cout<>operation; 189 | 190 | switch(operation) { 191 | case'S':{ 192 | cout<<"\nEnter \n\"A\" for assending order\n\"D\" for deccending order : "; 193 | cin>>choose; 194 | if(choose == 'A' || choose == 'a' || choose == 'D' || choose == 'd') { 195 | selectionSort(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose); 196 | break; 197 | } 198 | else { 199 | cout<<"\nPlease enter valid operation"; 200 | break; 201 | } 202 | for(int i = 0; i < 85; i++) { 203 | cout<<"*"; 204 | } 205 | } 206 | case's':{ 207 | cout<<"\nEnter \n\"A\" for assending order\n\"D\" for deccending order : "; 208 | cin>>choose; 209 | if(choose == 'A' || choose == 'a' || choose == 'D' || choose == 'd') { 210 | selectionSort(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose); 211 | break; 212 | } 213 | else { 214 | cout<<"\nPlease enter valid operation"; 215 | break; 216 | } 217 | for(int i = 0; i < 85; i++) { 218 | cout<<"*"; 219 | } 220 | } 221 | case'R': 222 | choose = 'a'; 223 | search(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose,Marks); 224 | break; 225 | case 'r': 226 | choose = 'a'; 227 | search(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose,Marks); 228 | break; 229 | case 'L': 230 | list(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size, Marks); 231 | break; 232 | case 'l': 233 | list(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size, Marks); 234 | break; 235 | case 'C': 236 | system("CLS"); 237 | break; 238 | case 'c': 239 | system("CLS"); 240 | break; 241 | case 'E': 242 | return 0; 243 | case 'e': 244 | return 0; 245 | 246 | default:{ 247 | cout<<"Please enter correct operaion"<>size; //size of array 270 | 271 | for(int i = 0; i < size; i++) { // loop for input roll numbers, subjects marks 272 | cout<<"*********************************** Input Format *********************************** "; 273 | cout<<"\nRollNumber calculusMarks EnglishMarks ProgrammingMarks SocialMarks DataSciencesMarks"<> rNumber[i]>> cMarks[i]>> eMarks[i]>> pMarks[i]>> sMarks[i]>> dMarks[i]; 275 | 276 | } 277 | 278 | computeWeightAge(totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,Marks); 279 | menu(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose,Marks); 280 | 281 | return 0; 282 | } 283 | -------------------------------------------------------------------------------- /gread sheet of students/Assignment4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fazeelkhalid/Cpp-Programming-practice-problems-and-solutions/84d203c99ed4882dbcf6216f4ecc1198f0c9a240/gread sheet of students/Assignment4.pdf -------------------------------------------------------------------------------- /gread sheet of students/gread sheet of students.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void computeWeightAge( float (&totalIndvidualMarks)[50], float cMarks[], float eMarks[], float pMarks[], float sMarks[], float dMarks[], int size,float &Marks) { 7 | Marks = 0; 8 | float weigthAge[5]; 9 | int totalMarks[5]; 10 | 11 | for(int i = 0; i < 85; i++) { 12 | cout<<"*"; 13 | } 14 | cout<>totalMarks[i]; 19 | } 20 | 21 | for(int i = 0; i < 85; i++) { 22 | cout<<"*"; 23 | } 24 | cout<> weigthAge[i]; 29 | Marks = Marks + weigthAge[i]; 30 | } 31 | for(int i = 0; i < 5; i++ ) { //total marks of students 32 | cMarks[i] = cMarks[i]/totalMarks[0]*weigthAge[0]; 33 | eMarks[i] = (eMarks[i]/totalMarks[1]*weigthAge[1]); 34 | pMarks[i] = (pMarks[i]/totalMarks[2]*weigthAge[2]); 35 | sMarks[i] =(sMarks[i]/totalMarks[3]*weigthAge[3]); 36 | dMarks[i] = (dMarks[i]/totalMarks[4]*weigthAge[4]); 37 | totalIndvidualMarks[i] =cMarks[i] + eMarks[i] + pMarks[i] + sMarks[i] + dMarks[i]; 38 | } 39 | } 40 | 41 | void swapNumber(float &firstNumber, float &secondNumber){ 42 | 43 | float temp; 44 | 45 | temp = firstNumber; 46 | firstNumber = secondNumber; 47 | secondNumber = temp; 48 | 49 | } 50 | void swapNumber(int &firstNumber, int &secondNumber){ 51 | 52 | int temp; 53 | 54 | temp = firstNumber; 55 | firstNumber = secondNumber; 56 | secondNumber = temp; 57 | 58 | } 59 | 60 | void selectionSort( int (&rNumber)[50],float (&totalIndvidualMarks)[50], float (&cMarks)[50], float (&eMarks)[50], float (&pMarks)[50], float (&sMarks)[50], float (&dMarks)[50], int size, char choose) { 61 | 62 | if(choose == 'A' || choose =='a') { // for Assending order 63 | 64 | for(int i = 0; i < size - 1; i++) { 65 | int small = rNumber[i]; 66 | int Sindex; 67 | bool found = false; 68 | for(int j = i+1; j < size; j++) { 69 | if(small > rNumber[j] ) { 70 | small = rNumber[j]; 71 | Sindex = j; 72 | found = true; 73 | } 74 | } 75 | if(found){ 76 | swapNumber(totalIndvidualMarks[i],totalIndvidualMarks[Sindex]); 77 | swapNumber(eMarks[i],eMarks[Sindex]); 78 | swapNumber(pMarks[i],pMarks[Sindex]); 79 | swapNumber(sMarks[i],sMarks[Sindex]); 80 | swapNumber(dMarks[i],dMarks[Sindex]); 81 | swapNumber(rNumber[i],rNumber[Sindex]); 82 | } 83 | } 84 | } 85 | 86 | if(choose == 'D' || choose =='d') { // for Assending order 87 | 88 | for(int i = 0; i < size - 1; i++) { 89 | int small = rNumber[i]; 90 | int Sindex; 91 | bool found = false; 92 | for(int j = i+1; j < size; j++) { 93 | if(small < rNumber[j] ) { 94 | small = rNumber[j]; 95 | Sindex = j; 96 | found = true; 97 | } 98 | } 99 | if(found){ 100 | swapNumber(totalIndvidualMarks[i],totalIndvidualMarks[Sindex]); 101 | swapNumber(eMarks[i],eMarks[Sindex]); 102 | swapNumber(pMarks[i],pMarks[Sindex]); 103 | swapNumber(sMarks[i],sMarks[Sindex]); 104 | swapNumber(dMarks[i],dMarks[Sindex]); 105 | swapNumber(rNumber[i],rNumber[Sindex]); 106 | } 107 | } 108 | } 109 | } 110 | 111 | void search(int (&rNumber)[50],float (&totalIndvidualMarks)[50],float (&cMarks)[50],float (&eMarks)[50],float (&pMarks)[50],float (&sMarks)[50],float (&dMarks)[50],int size,char choose,float Marks) { 112 | 113 | int studentSearch; 114 | int end; 115 | int middle; 116 | 117 | bool present = false; 118 | end = size - 1; // 0 119 | 120 | selectionSort(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose); 121 | 122 | cout<<"\nEnter roll number for searching : "; 123 | cin>>studentSearch; 124 | 125 | for(int starting = 0; starting <= end;) { 126 | middle = (starting+end) / 2; 127 | if(studentSearch == rNumber[middle]) { // for list of student 128 | cout<<"\nStudent Roll Number : "< rNumber[middle]){ 140 | starting = middle+1; 141 | } 142 | else 143 | end = middle-1; 144 | } 145 | if(!present) { 146 | cout<>operation; 189 | 190 | switch(operation) { 191 | case'S':{ 192 | cout<<"\nEnter \n\"A\" for assending order\n\"D\" for deccending order : "; 193 | cin>>choose; 194 | if(choose == 'A' || choose == 'a' || choose == 'D' || choose == 'd') { 195 | selectionSort(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose); 196 | break; 197 | } 198 | else { 199 | cout<<"\nPlease enter valid operation"; 200 | break; 201 | } 202 | for(int i = 0; i < 85; i++) { 203 | cout<<"*"; 204 | } 205 | } 206 | case's':{ 207 | cout<<"\nEnter \n\"A\" for assending order\n\"D\" for deccending order : "; 208 | cin>>choose; 209 | if(choose == 'A' || choose == 'a' || choose == 'D' || choose == 'd') { 210 | selectionSort(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose); 211 | break; 212 | } 213 | else { 214 | cout<<"\nPlease enter valid operation"; 215 | break; 216 | } 217 | for(int i = 0; i < 85; i++) { 218 | cout<<"*"; 219 | } 220 | } 221 | case'R': 222 | choose = 'a'; 223 | search(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose,Marks); 224 | break; 225 | case 'r': 226 | choose = 'a'; 227 | search(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose,Marks); 228 | break; 229 | case 'L': 230 | list(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size, Marks); 231 | break; 232 | case 'l': 233 | list(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size, Marks); 234 | break; 235 | case 'C': 236 | system("CLS"); 237 | break; 238 | case 'c': 239 | system("CLS"); 240 | break; 241 | case 'E': 242 | return 0; 243 | case 'e': 244 | return 0; 245 | 246 | default:{ 247 | cout<<"Please enter correct operaion"<>size; //size of array 270 | 271 | for(int i = 0; i < size; i++) { // loop for input roll numbers, subjects marks 272 | cout<<"*********************************** Input Format *********************************** "; 273 | cout<<"\nRollNumber calculusMarks EnglishMarks ProgrammingMarks SocialMarks DataSciencesMarks"<> rNumber[i]>> cMarks[i]>> eMarks[i]>> pMarks[i]>> sMarks[i]>> dMarks[i]; 275 | 276 | } 277 | 278 | computeWeightAge(totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,Marks); 279 | menu(rNumber,totalIndvidualMarks, cMarks, eMarks, pMarks, sMarks, dMarks, size,choose,Marks); 280 | 281 | return 0; 282 | } 283 | -------------------------------------------------------------------------------- /input from file and store it in array/input from file and store it in array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | char ch; 6 | int array[5]; 7 | int i = 0; 8 | int condition = 0; 9 | FILE *fp; 10 | 11 | fp = fopen("input.txt", "r"); 12 | 13 | while((ch = fgetc(fp))!= EOF) { 14 | if(ch != ',') { 15 | 16 | if(!condition) { 17 | array[i] = ch - 48; 18 | condition++; 19 | } 20 | else { 21 | array[i] = array[i] * 10 + (ch - 48); 22 | } 23 | } 24 | else { 25 | i++; 26 | condition = 0; 27 | } 28 | } 29 | 30 | fclose(fp); 31 | for(int i = 0; i < 5; i++) { 32 | printf("%d\n",array[i]); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /input from file check is number and perform operation/input from file check is number and perform operation .cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() { 5 | 6 | FILE *file; 7 | char ch, ope; 8 | int first= 0, second= 0, result; 9 | bool is_first_number = true; 10 | bool is_second_number = true; 11 | 12 | file = fopen("input.txt", "r"); 13 | 14 | while((ch = fgetc(file))!= EOF) { 15 | 16 | if(is_first_number) { 17 | if(ch>= '0' && ch<= '9') { 18 | first= first * 10 + (ch - 48); 19 | } 20 | } 21 | 22 | else { 23 | if(ch>= '0' && ch<= '9') 24 | second= second * 10 + (ch - 48); 25 | } 26 | if(is_second_number) { 27 | if(ch==37||ch==42||ch==43||ch==45||ch==47) { 28 | ope= ch; 29 | is_first_number = false; 30 | is_second_number = false; 31 | } 32 | } 33 | printf("%c is not a number\n",ch); 34 | } 35 | 36 | switch(ope) { 37 | case '-': 38 | result = first - second; 39 | printf("subtraction = %d", result); 40 | break; 41 | 42 | case '+': 43 | result = first + second; 44 | printf("sum = %d", result); 45 | break; 46 | 47 | case '*': 48 | result = first * second; 49 | printf("multiply = %d", result); 50 | break; 51 | 52 | case '/': 53 | result =first / second; 54 | printf("division = %d", result); 55 | break; 56 | 57 | case '%': 58 | result = first % second; 59 | printf("MOD = %d", result); 60 | break; 61 | 62 | default: 63 | printf("Please choose only \"SUM DIV MUL SUB MOD\" operation"); 64 | } 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /input from file store it in array and sort it/input from file store it in array and sort it.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | char ch; 6 | int array[5]; 7 | int i = 0; 8 | int number; 9 | int condition = 0; 10 | FILE *fp; 11 | 12 | fp = fopen("input.txt", "r"); 13 | 14 | while((ch = fgetc(fp))!= EOF) { 15 | if(ch != ',') { 16 | 17 | if(!condition) { 18 | array[i] = ch - 48; 19 | condition++; 20 | } 21 | else { 22 | array[i] = array[i] * 10 + (ch - 48); 23 | } 24 | } 25 | else { 26 | i++; 27 | condition = 0; 28 | } 29 | } 30 | 31 | fclose(fp); 32 | 33 | for(int i = 0; i < 5; i++) { 34 | 35 | } 36 | 37 | for(int i = 4; i >= 0; i--) { 38 | for(int j = i - 1; j >= 0; j--) { 39 | if(array[i] 2 | 3 | int main() { 4 | 5 | FILE *file; 6 | char ch; 7 | char ope; 8 | int first = 0; 9 | int second = 0; 10 | int result; 11 | bool is_first_number = true; 12 | bool operator_variable = true; 13 | bool error_condition = true; 14 | 15 | file = fopen("input.txt", "r"); 16 | 17 | while((ch = fgetc(file))!= EOF) { 18 | 19 | if(is_first_number) { 20 | 21 | if(ch>= '0' && ch<= '9') { 22 | first= first * 10 + (ch - 48); 23 | } 24 | } 25 | else if(ch>= '0' && ch<= '9') { 26 | second= second * 10 + (ch - 48); 27 | } 28 | 29 | if(ch=='-' || ch=='+' || ch=='*' || ch=='/' || ch=='%') { 30 | if(operator_variable) { 31 | ope= ch; 32 | is_first_number = false; 33 | operator_variable = false; 34 | } 35 | else { 36 | printf("Wrong input"); 37 | error_condition = false; 38 | break; 39 | } 40 | } 41 | else if(ch < '0' || ch > '9') { 42 | printf("Wrong input"); 43 | error_condition = false; 44 | break; 45 | } 46 | 47 | } 48 | 49 | if(error_condition) { 50 | switch(ope) { 51 | case '-': 52 | result = first - second; 53 | printf("subtraction = %d", result); 54 | break; 55 | 56 | case '+': 57 | result = first + second; 58 | printf("sum = %d", result); 59 | break; 60 | 61 | case '*': 62 | result = first * second; 63 | printf("multiply = %d", result); 64 | break; 65 | 66 | case '/': 67 | result =first / second; 68 | printf("division = %d", result); 69 | break; 70 | 71 | case '%': 72 | result = first % second; 73 | printf("MOD = %d", result); 74 | break; 75 | 76 | } 77 | } 78 | 79 | fclose(file); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /input from user and check number is binary or not/Assignment2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fazeelkhalid/Cpp-Programming-practice-problems-and-solutions/84d203c99ed4882dbcf6216f4ecc1198f0c9a240/input from user and check number is binary or not/Assignment2.pdf -------------------------------------------------------------------------------- /input from user and check number is binary or not/input from user and check number is binary or not.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int binary; 8 | int remainder; 9 | 10 | bool is_binary = true; 11 | 12 | cout<<"Please enter binary number"; 13 | cin>>binary; 14 | if(binary >= 0){ 15 | 16 | while(binary > 0) { 17 | remainder = binary % 10; 18 | binary /= 10; 19 | 20 | if(remainder%2 >= 1) { 21 | is_binary = false; 22 | binary = 0; 23 | } 24 | } 25 | 26 | if(is_binary) { 27 | cout<<"you entered a binary number"; 28 | } 29 | else{ 30 | cout<<"you enterd a decimal number"; 31 | } 32 | } 33 | else{ 34 | cout<<"you enterd a decimal number"; 35 | } 36 | 37 | return 0; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /input total student ,total marks,and obtain marks and display its graph/Assignment2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fazeelkhalid/Cpp-Programming-practice-problems-and-solutions/84d203c99ed4882dbcf6216f4ecc1198f0c9a240/input total student ,total marks,and obtain marks and display its graph/Assignment2.pdf -------------------------------------------------------------------------------- /input total student ,total marks,and obtain marks and display its graph/input total student ,total marks,and obtain marks and display its graph.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int totalStudent; 8 | int totalMarks; 9 | float obtainMarks; 10 | float percentage; 11 | int a = 0; 12 | int b= 0; 13 | int c= 0; 14 | int d= 0; 15 | int f= 0; 16 | 17 | cout<<"Enter total student :"; 18 | cin>>totalStudent; 19 | cout<<"Enter total marks :"; 20 | cin>>totalMarks; 21 | 22 | while(totalStudent > 0) { 23 | cout<<"obtain Marks :"; 24 | cin>>obtainMarks; 25 | 26 | percentage = (obtainMarks / totalMarks) * 100; 27 | 28 | if(percentage >= 90) { 29 | a++; 30 | } 31 | else if(percentage >= 75 && percentage < 90) { 32 | b++; 33 | } 34 | else if(percentage >= 60 && percentage < 75 ) { 35 | c++; 36 | } 37 | else if(percentage >= 50 && percentage < 60) { 38 | d++; 39 | } 40 | else 41 | f++; 42 | 43 | totalStudent--; 44 | } 45 | cout< 0; a--) { 48 | cout<<"*"; 49 | } 50 | 51 | cout< 0; b--) { 54 | cout<<"*"; 55 | } 56 | 57 | cout< 0; c--) { 60 | cout<<"*"; 61 | } 62 | 63 | cout< 0; d--) { 66 | cout<<"*"; 67 | } 68 | 69 | cout< 0; f--) { 72 | cout<<"*"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /left down triangle with loop/left down triangle with loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int i,a,b; 6 | printf("Enter number of lines that you want to display : "); 7 | scanf("%d",&b); 8 | for(i=1;i<=b;i++) 9 | { 10 | for(a=b;a>=i;a--) 11 | { 12 | printf("*"); 13 | } 14 | printf("\n"); 15 | } 16 | getch (); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /left-upward-triangle/left-upward-triangle .cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int i,a,b; 5 | printf("enter number of rows you want to display : "); 6 | scanf("%d",&b); 7 | for(i=1;i<=b;i++) 8 | { 9 | for(a=1;a<=i;a++) 10 | { 11 | printf("*"); 12 | } 13 | printf("\n"); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /ll gram inside a rectangle/ll gram inside a rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int row; 6 | printf("Enter number of rows that you want to display : "); 7 | scanf("%d", &row); 8 | 9 | for(int i=1; i<=row; i++) { 10 | for(int j=(row); j>=i; j--) { 11 | printf("*"); 12 | } 13 | 14 | for(int k=1; k=i; l--) { 23 | printf("*"); 24 | } 25 | 26 | printf("\n"); 27 | } 28 | 29 | for(int i=1; i<=row; i++) { 30 | for(int j=1; j<=i; j++) { 31 | printf("*"); 32 | } 33 | 34 | for(int k=i; k 2 | 3 | using namespace std; 4 | 5 | int fraction (int numerator, int denomerator, int &answerNumerator, int &answerDenomerator) { 6 | 7 | if(numerator > 0 && denomerator > 0){ 8 | int i; 9 | 10 | i = (numerator < denomerator)? numerator: denomerator; 11 | 12 | for(i; i > 1; i--) { 13 | if(numerator % i == 0 && denomerator % i == 0){ 14 | break; 15 | } 16 | } 17 | answerNumerator = numerator / i; 18 | answerDenomerator = denomerator / i; 19 | 20 | return 1; 21 | } 22 | else 23 | return 0; 24 | } 25 | 26 | int main() { 27 | 28 | int numerator; 29 | int denomerator; 30 | int answerNumerator; 31 | int answerDenomerator; 32 | int itrate; 33 | 34 | cout<<"Enter Numerator"; 35 | cin>>numerator; 36 | cout<<"Enter Denomerator"; 37 | cin>> denomerator; 38 | 39 | itrate = fraction(numerator, denomerator,answerNumerator,answerDenomerator); 40 | 41 | if(!itrate) { 42 | cout<<"Pleace input non negative and non zero number\n"; 43 | system("pause"); 44 | return 0; 45 | } 46 | else { 47 | cout<<"Before reducing form : "< 2 | 3 | using namespace std; 4 | 5 | class Queue { 6 | private: 7 | int array[5]; 8 | int size; 9 | 10 | public: 11 | Queue(){ 12 | size = 0; 13 | } 14 | 15 | void enqueue(int a) { 16 | if(!isFull()) { 17 | array[size] = a; 18 | size++; 19 | } 20 | else 21 | cout<<"Queue full"; 22 | } 23 | 24 | int dequeue() { 25 | size--; 26 | return array[size]; 27 | } 28 | 29 | bool isFull() { 30 | return this->size == 5; 31 | } 32 | 33 | bool isEmpty() { 34 | return size == 0; 35 | } 36 | 37 | int top() { 38 | return array[size - 1]; 39 | } 40 | 41 | int bottom() { 42 | return array[0]; 43 | } 44 | 45 | 46 | }; 47 | 48 | int main() { 49 | 50 | Queue a; 51 | a.enqueue(126); 52 | a.enqueue(112); 53 | a.enqueue(122); 54 | a.enqueue(127); 55 | a.enqueue(13); 56 | 57 | a.dequeue(); 58 | 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /read data from file and opertion on it/read data from file and opertion on it.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | 6 | FILE *b; 7 | char ch, ope= 'a'; 8 | int first= 0, second= 0, a; 9 | bool is_first_number = true; 10 | 11 | b = fopen("input.txt", "r"); 12 | 13 | while((ch = fgetc(b))!= EOF) { 14 | if(is_first_number) { 15 | if(ch>= '0' && ch<= '9') { 16 | first= first * 10 + (ch - 48); 17 | } 18 | } 19 | else { 20 | second= second * 10 + (ch - 48); 21 | } 22 | 23 | if(ch>= 37 && ch<= 47) { 24 | ope= ch; 25 | is_first_number = false; 26 | } 27 | } 28 | 29 | switch(ope) { 30 | case '-': 31 | a = first - second; 32 | printf("subtraction = %d", a); 33 | break; 34 | 35 | case '+': 36 | a = first + second; 37 | printf("sum = %d", a); 38 | break; 39 | 40 | case '*': 41 | a = first * second; 42 | printf("multiply = %d", a); 43 | break; 44 | 45 | case '/': 46 | a =first / second; 47 | printf("division = %d", a); 48 | break; 49 | 50 | case '%': 51 | a = first % second; 52 | printf("MOD = %d", a); 53 | break; 54 | 55 | default: 56 | printf("Please choose only \"SUM DIV MUL SUB MOD\" operation"); 57 | } 58 | getch(); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /rectangle by Class/rectangle by Class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct Rectangle { 6 | private: 7 | float height; 8 | float width; 9 | float area; 10 | 11 | public: 12 | Rectangle() { 13 | height = 0; 14 | width = 0; 15 | area = height * width; 16 | } 17 | 18 | Rectangle(float h, float w) { 19 | height = h; 20 | width = w; 21 | area = h * w; 22 | } 23 | 24 | void print() { 25 | cout<<"Height: "<height<<"\nWidth: " << this->width<<"\nArea: "<height = h; 30 | this->area = this->height * this->width; 31 | } 32 | 33 | void setWidth(float w) { 34 | this->width = w; 35 | this->area = this->height * this->width; 36 | } 37 | }; 38 | 39 | int main() { 40 | struct Rectangle r(90, 60); 41 | r.print(); 42 | cout< 2 | 3 | int main() { 4 | int a; 5 | int number[5]; 6 | for(int i = 0; i < 5; i++) { 7 | printf("Enter number : "); 8 | scanf("%d",&number[i]); 9 | } 10 | 11 | for(int i = 0, j = 1; i < 5; i++,j++) { 12 | 13 | a = number[i]; 14 | number[i] = number[j]; 15 | number[j] = a; 16 | 17 | } 18 | 19 | for(int i = 0; i < 5; i++) { 20 | printf("%d",number[i]); 21 | printf(","); 22 | } 23 | 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /reverse of array/reverse of array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int j; 5 | int number[5]; 6 | int reverse[5]; 7 | 8 | for(int i = 0; i < 5; i++) { 9 | printf("input numbers: "); 10 | scanf("%d", &number[i]); 11 | } 12 | 13 | for(int i = 4; i >= 0; i-- ) { 14 | if(j <5) { 15 | reverse[j] = number[i]; 16 | j++; 17 | } 18 | } 19 | 20 | for(int i = 0; i < 5; i++) { 21 | number[i] = reverse[i]; 22 | 23 | } 24 | 25 | for(int i = 0; i < 5; i++) { 26 | printf("%d",number[i]); 27 | printf(","); 28 | } 29 | 30 | return 0; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /reverse string/reverse string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char a[10]; 6 | printf("enter you name "); 7 | scanf("%s", &a); 8 | 9 | for(int i=10; i>=0;i-- ) { 10 | printf("%C",a[i]); 11 | } 12 | 13 | return 0; 14 | } 15 | panding 16 | -------------------------------------------------------------------------------- /right down triangle with loop/right down triangle with loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, j, k, row; 6 | printf("Enter number of rows you want to display : " ); 7 | scanf("%d",&row); 8 | 9 | for(i=1; i<=row; i++) { 10 | for(k=1; k=i; j--) { 15 | printf("*"); 16 | } 17 | 18 | printf("\n"); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /right upward triangle with loop/right upward triangle with loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int a, b, c, d; 6 | printf("enter number of rows you want to display : "); 7 | scanf("%d", &d); 8 | 9 | for(a=1; a<=d; a++) { 10 | for(c=d; c>a; c--) { 11 | printf(" "); 12 | } 13 | 14 | for(b=1; b<=a; b++) { 15 | printf("*"); 16 | } 17 | 18 | printf("\n"); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /right+left up_triangle with loop/right+left up_triangle with loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int row; 6 | printf("Enter number of rows that you want to display : "); 7 | scanf("%d", &row); 8 | 9 | 10 | for(int i=1; i<=row; i++) { 11 | for(int j=1; j<=i; j++) { 12 | printf("*"); 13 | } 14 | 15 | for(int k=i; k 2 | #include 3 | 4 | int main() { 5 | int i, j, k, l, m, row; 6 | printf("Enter number of rows that you want to display : "); 7 | scanf("%d", &row); 8 | 9 | for(int i=1; i<=row; i++) { 10 | for(j=(row); j>=i; j--) { 11 | printf("*"); 12 | } 13 | 14 | for(k=1; k=i; l--) { 23 | printf("*"); 24 | } 25 | 26 | printf("`\n"); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /space invaders console based c++ projects/READ ME.txt: -------------------------------------------------------------------------------- 1 | add mygraphics.h header file before use game 2 | -------------------------------------------------------------------------------- /space invaders console based c++ projects/mygraphics.h: -------------------------------------------------------------------------------- 1 | #ifndef MYGRAPHICS_H_ 2 | #define MYGRAPHICS_H_ 3 | 4 | #include 5 | 6 | // function prototypes 7 | 8 | void drawLine(int x1,int y1,int x2,int y2,int colour); // draws a line between two points given their x-y coordinates in gray-scale 9 | void drawLine(int x1,int y1,int x2,int y2,int r, int g, int b); // draws a line between two points given their x-y coordinates using RGB colouring 10 | void drawRectangle(int x1, int y1, int x2, int y2, int R, int G, int B); // draws a rectangle using top-left and bottom-right x-y coordinates with a border using RGB colouring 11 | void drawRectangle(int x1, int y1, int x2, int y2, int R, int G, int B, int FR, int FG, int FB ); // draws a rectangle using top-left and bottom-right x-y coordinates with separate border and fill colours 12 | void drawEllipse(int x1, int y1, int x2, int y2,int R, int G, int B); // draws a rectangle-bounded ellipse using top-left and bottom-right x-y coordinates with a border using RGB colouring 13 | void drawEllipse(int x1, int y1, int x2, int y2,int R, int G, int B, int FR, int FG, int FB); // draw a rectangle-bounded ellipse using top-left and bottom-right x-y coordinates with separate border and fill colours 14 | void cls(); // clears the screen 15 | void delay(int ms); // waits for some time (in milli-seconds) 16 | char getKey(); // gets key typed into the console without waiting for the input 17 | void getWindowDimensions(int& width, int& height); // gets width and height of the window 18 | void getConsoleWindowDimensions(int& width, int& height); // gets width and height of console window (in character mode) 19 | void gotoxy(int x,int y); // sets console cursor on given x-y coordinates 20 | void showConsoleCursor(bool showFlag); // shows or hides the cursor 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | // function definitions 32 | 33 | void drawLine(int x1,int y1,int x2,int y2,int colour){ 34 | drawLine(x1,y1,x2,y2,colour,colour,colour); 35 | } 36 | 37 | void drawLine(int x1, int y1, int x2, int y2,int R, int G, int B) //use three 3 integers if you want colored lines. 38 | { 39 | HWND consoleHandle = GetConsoleWindow(); 40 | HDC deviceContext = GetDC(consoleHandle); 41 | 42 | //change the colour by changing the values in RGB (from 0-255) to get shades of gray. For other colors use 3 integers for color. 43 | HPEN pen = CreatePen(PS_SOLID,2,RGB(R,G,B)); //2 is the width of the pen 44 | SelectObject(deviceContext,pen); 45 | MoveToEx(deviceContext,x1,y1,NULL); 46 | LineTo(deviceContext,x2, y2); 47 | DeleteObject(pen); 48 | ReleaseDC(consoleHandle, deviceContext); 49 | } 50 | 51 | void drawRectangle(int x1, int y1, int x2, int y2, int R, int G, int B){ 52 | drawRectangle(x1, y1, x2, y2, R, G, B, 0,0,0); 53 | } 54 | 55 | void drawRectangle(int x1, int y1, int x2, int y2, int R, int G, int B, int FR, int FG, int FB ) 56 | { 57 | HWND consoleHandle = GetConsoleWindow(); 58 | HDC deviceContext = GetDC(consoleHandle); 59 | 60 | //change the colour by changing the values in RGB (from 0-255) 61 | HPEN pen = CreatePen(PS_SOLID,2,RGB(R,G,B)); 62 | SelectObject(deviceContext,pen); 63 | HBRUSH brush = CreateSolidBrush(RGB(FR,FG,FB)); 64 | SelectObject(deviceContext,brush); 65 | Rectangle(deviceContext,x1,y1,x2,y2); 66 | DeleteObject(pen); 67 | DeleteObject(brush); 68 | ReleaseDC(consoleHandle, deviceContext); 69 | 70 | } 71 | 72 | void drawEllipse(int x1, int y1, int x2, int y2,int R, int G, int B){ 73 | drawEllipse(x1, y1, x2, y2, R, G, B, 0, 0, 0); 74 | } 75 | 76 | void drawEllipse(int x1, int y1, int x2, int y2,int R, int G, int B,int FR,int FG,int FB) 77 | { 78 | HWND consoleHandle = GetConsoleWindow(); 79 | HDC deviceContext = GetDC(consoleHandle); 80 | 81 | //change the colour by changing the values in RGB (from 0-255) 82 | 83 | HPEN pen = CreatePen(PS_SOLID,2,RGB(R,G,B)); 84 | SelectObject(deviceContext,pen); 85 | HBRUSH brush = CreateSolidBrush(RGB(FR,FG,FB)); // fill colour 86 | SelectObject(deviceContext,brush); 87 | Ellipse(deviceContext,x1,y1,x2,y2); 88 | DeleteObject(pen); 89 | DeleteObject(brush); 90 | ReleaseDC(consoleHandle, deviceContext); 91 | 92 | } 93 | 94 | void cls() 95 | { 96 | COORD coordScreen = { 0, 0 }; // home for the cursor 97 | DWORD cCharsWritten; 98 | CONSOLE_SCREEN_BUFFER_INFO csbi; 99 | DWORD dwConSize; 100 | 101 | HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 102 | 103 | if( !GetConsoleScreenBufferInfo( consoleHandle, &csbi )) 104 | { 105 | return; 106 | } 107 | 108 | dwConSize = csbi.dwSize.X * csbi.dwSize.Y; 109 | 110 | FillConsoleOutputCharacter( consoleHandle, // Handle to console screen buffer 111 | (TCHAR) ' ', // Character to write to the buffer 112 | dwConSize, // Number of cells to write 113 | coordScreen, // Coordinates of first cell 114 | &cCharsWritten ); // Receive number of characters written 115 | 116 | } 117 | 118 | void delay(int ms) 119 | { 120 | Sleep(ms); 121 | } 122 | 123 | char getKey() 124 | { 125 | HANDLE consoleHandle = GetStdHandle(STD_INPUT_HANDLE); 126 | DWORD size = 1; 127 | INPUT_RECORD input[1]; 128 | DWORD events = 0; 129 | char key = '\0'; 130 | 131 | if (PeekConsoleInput(consoleHandle,input,size,&events)){ 132 | if (input[0].EventType == KEY_EVENT){ 133 | key = input[0].Event.KeyEvent.uChar.AsciiChar; 134 | FlushConsoleInputBuffer(consoleHandle); 135 | return key; 136 | } 137 | } 138 | 139 | return key; // returns NULL if no input event recorded 140 | } 141 | 142 | void getWindowDimensions(int& width, int& height) 143 | { 144 | HWND consoleHandle = GetConsoleWindow(); 145 | RECT rc; 146 | GetClientRect(consoleHandle, &rc); 147 | width = rc.right; 148 | height = rc.bottom; 149 | } 150 | 151 | void getConsoleWindowDimensions(int& width, int& height) 152 | { 153 | HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 154 | CONSOLE_SCREEN_BUFFER_INFO csbi; 155 | 156 | if( !GetConsoleScreenBufferInfo( consoleHandle, &csbi )) { 157 | return; 158 | } 159 | 160 | width = csbi.srWindow.Right; 161 | height = csbi.srWindow.Bottom; 162 | } 163 | 164 | void gotoxy(int x, int y) 165 | { 166 | COORD coord; 167 | coord.X = x; 168 | coord.Y = y; 169 | 170 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); 171 | } 172 | 173 | 174 | void showConsoleCursor(bool flag) 175 | { 176 | HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 177 | 178 | CONSOLE_CURSOR_INFO cursorInfo; 179 | 180 | GetConsoleCursorInfo(consoleHandle, &cursorInfo); 181 | cursorInfo.bVisible = flag; // show or hide if flag is true or false respectively 182 | SetConsoleCursorInfo(consoleHandle, &cursorInfo); 183 | } 184 | 185 | #endif /* MYGRAPHICS_H_ */ -------------------------------------------------------------------------------- /space invaders console based c++ projects/space invaders console based c++ projects.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "mygraphics.h" 6 | 7 | using namespace std; 8 | 9 | int allienX; 10 | int allienY; 11 | int HFireY; 12 | int HFireX; 13 | bool is_destroy = true; // hero fire destroy or not 14 | bool is_fire = false; // fire by hero or not 15 | int allienNumber[8]; //select which allien will fire 16 | int counter = 0; //count allien 17 | int allienFireX[8]; // x component of allien fire 18 | int allienFireY[8]; // y component of allien fire 19 | int index = 0; // handle allienFireY and allienFireX array 20 | int allDestroy; // it will tell all destroy or not; 21 | int numberOfFire = 0; // number of fire by allien 22 | bool assignJustOnce; // refire by allien 23 | bool first_call = true; //it will call random function just once 24 | int lives = 10; // it give the live to hero 25 | int score = 0; // store the score 26 | 27 | BOOL setxy(int x, int y) {// this will set cursor position 28 | COORD c = {x,y}; 29 | return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c); 30 | } 31 | 32 | void delaay(int number_of_seconds) { 33 | int milli_seconds = 100 * number_of_seconds; // Converting time into milli_seconds 34 | clock_t start_time = clock(); // Stroing start time 35 | while (clock() < start_time + milli_seconds); // looping till required time is not acheived 36 | } 37 | 38 | bool one_decrease_at_once = true; // only decrease one lives 39 | 40 | void randomFire() { 41 | 42 | srand(time(0)); 43 | for(int i = 1; i < 8; i++) { 44 | allienNumber[i] = rand() % 32; 45 | } 46 | assignJustOnce = true; 47 | one_decrease_at_once = true; // only decrease one lives 48 | } 49 | int s = 50; 50 | int t = 150; 51 | 52 | int defenderX; // hero x component 53 | int defenderY; // hero y component 54 | 55 | void destroyHero(int heroX, int heroY){ 56 | s--; 57 | if(s == 0){ 58 | t--; 59 | s=50; 60 | } 61 | for(int i = 0; i <= 7; i++) { 62 | if(heroY == allienFireY[i]){ 63 | for(int j = 0; j <= 7; j++) { 64 | if(heroX == allienFireX[index]) { 65 | if(one_decrease_at_once) // only decrease one lives 66 | lives--; 67 | one_decrease_at_once = false; 68 | } 69 | 70 | } 71 | } 72 | } 73 | } 74 | 75 | int dAllien[] = {1,12,13,14,15,16,17,18,19,10,18,17,16,15,14,13,14,15,16,17,18,19,10,14,14,15,16,17,1,1,1,1}; // indicate which allien is alive 76 | void drawAllienFire(int x, int y) { //draw and move allien fire 77 | if(assignJustOnce) { // 78 | allienFireX[index] = x; 79 | allienFireY[index] = y; 80 | numberOfFire ++; 81 | allDestroy = 0; 82 | } 83 | if(allienFireY[index] < 29) { 84 | setxy(allienFireX[index], allienFireY[index]); 85 | cout << char(186); 86 | } 87 | else{ // it will draw space if fire reach at a certain place 88 | setxy(allienFireX[index], allienFireY[index]); 89 | cout << char(32); 90 | allienFireY[index] = 28; 91 | allDestroy ++; 92 | } 93 | destroyHero( defenderX, defenderY); 94 | 95 | allienFireY[index]++; 96 | index++; 97 | if(index == 7){ 98 | index = 0; 99 | assignJustOnce = false; 100 | } 101 | } 102 | 103 | int i = 0; // limitization of allienFireX and allienFireY array 104 | 105 | void DrawAllien(int x, int y, int width, int height, int curPosX=0, int curPosY=0) {// Giving a single allien 106 | 107 | 108 | setxy(x+1 , y); 109 | for(int i = 1; i < width; i++) 110 | cout << char(248); 111 | cout << char(); 112 | setxy(x,height + y); 113 | cout << char(200); 114 | 115 | for(int i = 1; i < width; i++) 116 | cout << char(94); 117 | cout << char(188); 118 | 119 | for(int i = y + 1; i < height + y; i++) { 120 | setxy(x,i); 121 | cout<< char(186); 122 | setxy(x + width,i); 123 | cout<< char(186); 124 | } 125 | counter ++; // count number of alliens 126 | if(first_call) { 127 | randomFire(); 128 | first_call = false; 129 | } 130 | 131 | if(allDestroy >= 100) { // it will call randomFire when all fires are destroy 132 | first_call = true; 133 | allDestroy = 0; 134 | } 135 | 136 | for(int i = 0; i < 8; i++) { //it will draw fire 137 | if(counter == allienNumber[i]){ 138 | drawAllienFire(x+1,y+2); 139 | } 140 | } 141 | if(counter == 32) { 142 | counter = 0; 143 | } 144 | 145 | setxy(curPosX,curPosY); 146 | } 147 | 148 | int COUNT = 0; 149 | int aNumber = 0; //index for the status of allien 150 | bool destroyAllien = true; //destroy only one allien at a time 151 | 152 | void Allien(int initialValueX,int initialValueY) { // for multiple allien 153 | 154 | for(int y = initialValueY; y < 10 + initialValueY ; y += 3 ) { 155 | for(int x = initialValueX + 20; x < 100 + initialValueX; x += 10) { 156 | if(dAllien[aNumber]) { 157 | DrawAllien(x, y, 3, 1, x , y); 158 | allienX = x; 159 | allienY = y; 160 | if(HFireX >= allienX - 1 && HFireX <= allienX + 4 && HFireY == allienY-2) 161 | if(destroyAllien) { 162 | dAllien[COUNT] = 0; 163 | score += 10; 164 | destroyAllien = false; 165 | is_destroy = true; 166 | is_fire = false; 167 | } 168 | } 169 | aNumber++; 170 | COUNT ++; 171 | if(COUNT == 32) { 172 | COUNT = 0; 173 | } 174 | if(aNumber == 32){ 175 | aNumber = 0; 176 | } 177 | } 178 | } 179 | } 180 | 181 | void hero(int heroX,int heroY,int curPosX = 0,int curPosY = 0) { // move hero 182 | 183 | setxy(heroX , heroY); //heroX + 1 , heroy 184 | cout << char(94); 185 | defenderX = heroX; 186 | defenderY = heroY; 187 | setxy(heroX , heroY + 1); //heroX + 1 , heroY + 1 188 | cout << char(178); 189 | setxy(curPosX,curPosY); 190 | } 191 | 192 | void heroFire(int heroX, int heroY,int allienX, int allienY) { //draw herro fire 193 | 194 | if(is_destroy){ 195 | HFireX = heroX; 196 | HFireY = heroY; 197 | destroyAllien = true; 198 | is_destroy = false; 199 | } 200 | int temp = allienY - 10; 201 | 202 | if(temp == HFireY){ 203 | is_destroy = true; 204 | is_fire = false; 205 | } 206 | setxy(HFireX , HFireY); 207 | cout<< char(94); 208 | HFireY--; 209 | } 210 | 211 | void remainingLive(int live){ 212 | for(int i = 0; i < live*4 ;i++) { 213 | cout<= 1 && i <= 20) { 230 | setxy(45,16); 231 | cout<<"Creating Temporary files"; 232 | } 233 | else if( i >= 20 && i<=40) { 234 | setxy(45,16); 235 | cout<<"Accessing Main Memory"; 236 | } 237 | else if(i >=40 && i<=48) { 238 | setxy(45,16); 239 | cout<<"Accessing Cache"; 240 | } 241 | else{ 242 | setxy(55,16); 243 | cout<<"Complete. "; 244 | } 245 | delaay(1); 246 | } 247 | 248 | delaay(10); 249 | 250 | } 251 | 252 | int mHeroX; // select speed for hero 253 | float mallienfX; // select forward speed for allien 254 | float mallienrx; // select reverse speed for allien 255 | void Instruction(){ 256 | char c; 257 | system("CLS"); 258 | showConsoleCursor(false); 259 | cout<<"******* INSTRUCTION *******\n"; 260 | cout<<"\"A\" for right movement\n"; 261 | cout<<"\"D\" for left movement\n"; 262 | cout<<"\"F\" for fire\n"; 263 | cout<<"\"Q\" for close game\n"; 264 | cout<<"Lives = 5\n"; 265 | cout<<"Press \'N\' for normal\n"; 266 | cout<<"Press \'M\' for medium\n"; 267 | cout<<"Press \'H\' for hard : "; 268 | reenter: 269 | cin >> c; 270 | if(c == 'n' || c == 'N') { 271 | t = 150; 272 | mHeroX = 2; 273 | mallienfX = 0.125; 274 | mallienrx = 0.25; 275 | } 276 | else if(c == 'm' || c == 'M') { 277 | t = 120; 278 | mHeroX = 4; 279 | mallienfX = 0.25; 280 | mallienrx = 0.5; 281 | } 282 | else if(c == 'h' || c == 'H') { 283 | t = 60; 284 | mHeroX = 7; 285 | mallienfX = 0.5; 286 | mallienrx = 1; 287 | } 288 | else { 289 | cout<<"\nPlease reenter : "; 290 | goto reenter; 291 | } 292 | cout<<"Time deadline "<= 100) { 476 | heroX = 100; 477 | } 478 | } 479 | 480 | void handle(char &move, int &heroX, int &HeroY, bool &gameOver,int &i, int &j){ 481 | if(move == 'd' || move == 'D'){ // move leftward 482 | heroX += mHeroX; 483 | } 484 | else if(move == 'a' || move == 'A') { //move rightward 485 | heroX -= mHeroX; 486 | } 487 | else if(move == 'f' || move == 'F') { // fire from hero 488 | is_fire = true; 489 | } 490 | else if (move == 'q' || move == 'Q') { 491 | i = 10; 492 | j = 10; 493 | gameOver = true; 494 | system("CLS"); 495 | } 496 | 497 | if(heroX <= 20) { //for restrict the movement of hero 498 | heroX = 20; 499 | } 500 | else if( heroX >= 100) { 501 | heroX = 100; 502 | } 503 | } 504 | 505 | int main() { 506 | 507 | int verticalMovement = 2; // vertical movement of hero 508 | char move; // for moving an hero 509 | int heroX = 45; 510 | int heroY = 26; 511 | int fireX; 512 | int fireY; 513 | float i; 514 | bool gameOver = false; 515 | Download(); 516 | Instruction(); 517 | while(!gameOver) { 518 | for(int j = 0; j < 10; j = j++ ) { // moves allien downward 519 | for(i = 0; i < 10; i = i + mallienfX) { //moves allien right left 520 | system("CLS"); 521 | showConsoleCursor(false); 522 | displayOnScreen (); 523 | Allien(i , verticalMovement ); 524 | hero(heroX, heroY); 525 | 526 | fireX = heroX; 527 | fireY = heroY; 528 | 529 | if(is_fire ) { 530 | heroFire( fireX, fireY, allienX, allienY); 531 | } 532 | 533 | if(kbhit()){ 534 | move = getch(); // input for movement of hero 535 | handle(move,heroX,heroY, gameOver, i,j); 536 | } 537 | if(lives == 0 || score == 320 || t == 0) { 538 | i = 10; 539 | j = 10; 540 | system("CLS"); 541 | gameOver = true; 542 | } 543 | } 544 | 545 | for(int i = 9; i > 0; i = i - mallienrx) { 546 | system("CLS"); 547 | showConsoleCursor(false); 548 | displayOnScreen (); 549 | Allien(i , verticalMovement ); 550 | hero(heroX, heroY); 551 | 552 | if(is_fire ) { 553 | heroFire( heroX, heroY, allienX, allienY); 554 | } 555 | if(kbhit()){ 556 | 557 | move = getch(); //movement of hero 558 | handle(move, heroX, heroY, gameOver,i,j); 559 | } 560 | if(lives == 0 || score == 320 || t == 0) { 561 | i = 0; 562 | system("CLS"); 563 | 564 | } 565 | } 566 | if(verticalMovement != 16) { 567 | verticalMovement++; 568 | } 569 | 570 | } 571 | } 572 | system ("CLS"); 573 | 574 | if(score == 320) 575 | congratulation(); 576 | else if ( lives == 0 || t == 0) 577 | gameover(); 578 | 579 | return 0; 580 | } 581 | 582 | -------------------------------------------------------------------------------- /stack of number/stack of numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Stack { 6 | private: 7 | int array[5]; 8 | int size; 9 | 10 | public: 11 | 12 | Stack() { 13 | size = 0; 14 | } 15 | 16 | void push(int val) { 17 | if(size < 5) { 18 | array[size] = val; 19 | size++; 20 | } 21 | else 22 | cout<<"Not enough sapce in stack"; 23 | } 24 | 25 | int pop() { 26 | if(size > 0) { 27 | size--; 28 | return array[size]; 29 | } 30 | else 31 | cout<<"Stack Empty"; 32 | } 33 | 34 | bool isFull() { 35 | if(this->size < 5) { 36 | return false; 37 | } 38 | else 39 | return true; 40 | } 41 | 42 | bool isEmpty() { 43 | if(size == 0) { 44 | return true; 45 | } 46 | else 47 | return false; 48 | } 49 | 50 | int top() { 51 | return array[--size]; 52 | } 53 | }; 54 | 55 | int main() { 56 | Stack s; 57 | 58 | s.push(43); 59 | s.push(90); 60 | s.push(64) 61 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | float first_Number = 10.398; 7 | float second_Number = 98.548; 8 | float sum; 9 | 10 | sum = first_Number + second_Number; 11 | 12 | cout<<"Sum: "<< (int)sum; 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /write in file/write in file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | FILE *fp; 6 | fp = fopen("fazeelkhalid.txt","w"); 7 | fprintf(fp , "abcdefghijklmnopqrstuvwxyz"); 8 | 9 | fclose(fp); 10 | return 0; 11 | } 12 | --------------------------------------------------------------------------------