From d883b358f40a4b4f05c5f1493d7debbe82156bac Mon Sep 17 00:00:00 2001 From: Kelash <58991510+KumarKelashMeghwar@users.noreply.github.com> Date: Sat, 23 Oct 2021 14:37:09 +0500 Subject: [PATCH] Added Some cpp programs --- Add-nums-with-bitwise.cpp | 27 ++++++++ matrix calculator.cpp | 128 ++++++++++++++++++++++++++++++++++++++ pointers.cpp | 15 +++++ prime number.cpp | 18 ++++++ reading files.cpp | 45 ++++++++++++++ switch statement.cpp | 23 +++++++ time conversion.cpp | 14 +++++ turnory operator.cpp | 12 ++++ 8 files changed, 282 insertions(+) create mode 100644 Add-nums-with-bitwise.cpp create mode 100644 matrix calculator.cpp create mode 100644 pointers.cpp create mode 100644 prime number.cpp create mode 100644 reading files.cpp create mode 100644 switch statement.cpp create mode 100644 time conversion.cpp create mode 100644 turnory operator.cpp diff --git a/Add-nums-with-bitwise.cpp b/Add-nums-with-bitwise.cpp new file mode 100644 index 0000000..3abd4fb --- /dev/null +++ b/Add-nums-with-bitwise.cpp @@ -0,0 +1,27 @@ +#include +int main() +{ + int number,number2,sum,carry; + + do{ + printf("Enter 1st Number: "); + scanf("%d",&number); + + printf("Enter 2nd Number: "); + scanf("%d",&number2); + + + while(number2!=0){ + sum= number ^ number2; + carry= (number & number2)<<1; + number=sum; + number2=carry; + } + + printf("Addition is: %d\n",number); + + + }while(true); + return 0; + +} diff --git a/matrix calculator.cpp b/matrix calculator.cpp new file mode 100644 index 0000000..a6a8139 --- /dev/null +++ b/matrix calculator.cpp @@ -0,0 +1,128 @@ +#include +#include +using namespace std; + +void setmatrix(int array[3][3]) + { + cout<<"Enter Values:\n"; + for(int i=0;i<3;i++) + { + for(int j=0;j<3;j++) + { + cout<<"("<>array[i][j]; + } + } + } + +void showmatrix(int array[3][3]) + { + for(int i=0;i<3;i++) + { + for(int j=0;j<3;j++) + {cout<>c; + switch(c) + { + case '*': + matrixmultiplication(A,B); + break; + + case '+': + matrixaddition(A,B); + break; + + case '-': + matrixsubtraction(A,B); + break; + + case '/': + matrixdivision(A,B); + break; + + default: + cout<<"Invalid operator!!!"; + + } + cout<<"\nDo u want to perform another operation again(y/n)? :"; + cin>>doagain; + } + + +} diff --git a/pointers.cpp b/pointers.cpp new file mode 100644 index 0000000..32ce12f --- /dev/null +++ b/pointers.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; +int main() +{ int h=5; +char c='Z'; + int* v; + v=&h; + char *b; + b=&c; + //b=&h; //error1= cannot convert 'int*' to 'char*' in assignment + cout<<"h= "< +#include +using namespace std; +int main() +{ + ifstream reading("C:/Users/zohaib hassan/Desktop/tuesday/filing/zhs.txt"); + char data[200]; + while(!reading.eof()) //or while(reading + { + reading.getline(data,200); + cout<>word) + { + if(word=="stored") + { + cout< +using namespace std; +int main() +{ int a; +cout<<"enter any integer ="; +cin>>a; + switch(a) + { case 60: + case 50: +// if cases r not identified in input then default will be executed. + case 40: + cout<<"A grade"; + break; + case 30: + case 20: + cout<<"D grade."; + break; + default: + cout<<"Any other grade than \"A\" or \"D\""; + } + + + } diff --git a/time conversion.cpp b/time conversion.cpp new file mode 100644 index 0000000..ef88c94 --- /dev/null +++ b/time conversion.cpp @@ -0,0 +1,14 @@ +#include +#include +using namespace std; +int main() +{ int hours,secs,mins; +cout<<"Enter no of hours= "; +cin>>hours; +mins=hours*60; +cout<<"Mins in given hours= "<