http://com-info4u.blogspot.com/ This document is all about the c++ codes. Here u can see how to write c++ writes for some basic program. For many more codes and resources please visit: http://com-info4u.blogspot.com/ see you there.. thank you...
Título original
write a program for pascal's triangle, fibonacci series, geometirc series, arthmetic series, matrix addition in object oriented fashion in C++....
http://com-info4u.blogspot.com/ This document is all about the c++ codes. Here u can see how to write c++ writes for some basic program. For many more codes and resources please visit: http://com-info4u.blogspot.com/ see you there.. thank you...
http://com-info4u.blogspot.com/ This document is all about the c++ codes. Here u can see how to write c++ writes for some basic program. For many more codes and resources please visit: http://com-info4u.blogspot.com/ see you there.. thank you...
Write a program that performs the matrix addition of size 3 X 3.
The program must ask the
user to enter all the elements of both 3 X 3 size matrices. The program must be object oriented. include<iostream> using namespace::std; class Matrixaddition { public: int userinput(); int result(); int i, j; private: int firstmatrix[3][3]; int secondmatrix[3][3]; int finalmatrix[3][3]; }; int Matrixaddition::userinput() { cout<<"\nPlease enter the elements for first matrix: \n"; for(i=0; i<3; i++) { for(j=0; j<3; j++) { cin>>firstmatrix[i][j]; } cout<<"\n"; } cout<<"\nPlease enter the elements for second matrix: \n"; for(i=0; i<3; i++) { for(j=0; j<3; j++) { cin>>secondmatrix[i][j]; } cout<<"\n"; } return 0; } int Matrixaddition::result() { cout<<"\nThe sum of the two matrices are: \n"; for(i=0; i<3; i++) { for(j=0; j<3; j++) { cout<<firstmatrix[i][j]+secondmatrix[i][j]<<" "; } cout<<"\n"; } return 0; } int main() { Matrixaddition M; M.userinput(); M.result(); } Using two dimensional array write a documented program which stores the 5 character long names of three students. #include<iostream> using namespace::std; class Matrixcharacter { public: void userinput(); void result(); private: char studentname[3][6]; int i, j; }; void Matrixcharacter::userinput() { cout<<"\nEnter the name of any three students, with max length of 5 characters"; for(i=0; i<3; i++) { for(j=0; j<5; j++) { cin>>studentname[i][j]; } } } void Matrixcharacter::result() { cout<<"\nThe entered students names are: \n"; for(i=0; i<3; i++) { for(j=0; j<5; j++) { cout<<studentname[i][j]; } cout<<"\n"; } } int main() { Matrixcharacter M; M.userinput(); M.result(); } Write an object oriented program for the pascal’s triangle. #include<iostream> #include<iomanip> using namespace::std; class Pascaltriangle { public: int fact (int); void userinput(); int number; private: int row, element; }; void Pascaltriangle::userinput() { cout<<"\nPlease enter the number of row you want to print:"; cin>>number; for(row=0; row<number; row++) { cout<<setw(number-row); for(element=0; element<row; element++) { cout<<fact(row)/(fact(row-element))/(fact(element)); cout<<" "; } cout<<"1"; cout<<"\n"; } } int Pascaltriangle::fact (int number) { if(number<=1) return 1; else return number*fact(number-1); } int main() { Pascaltriangle P; P.userinput(); P.fact(P.number); return 0; } Write an object oriented program for the Fibonacci series. #include<iostream> using namespace::std; class Fibonacci { public: int fibo(int); int number; void userinput(); int i; }; void Fibonacci::userinput() { cout<<"\nEnter the number of fibonacci elements you want to find:"; cin>>number; cout<<"\nThe fibonacci series up to "<<number<<" element is:\n"; for(i=0; i<number; i++) { cout<<fibo(i)<<"\t"; } } int Fibonacci::fibo(int number) { if (number<=1) return 1; else return fibo(number-1)+fibo(number-2); } int main() { Fibonacci F; F.userinput(); F.fibo(F.number); } Write an object oriented program for the Geometric series. #include<iostream> #include<cmath> using namespace::std; class Geometricseries { public: void userinput(); float calculation(float, float, int); float start, commonratio, newcommonratio; int numberofterms, i; }; void Geometricseries::userinput() { cout<<"\nPlease enter the start Number: "; cin>>start; cout<<"\n\t\tCommon Ratio:"; cin>>commonratio; cout<<"\n\t\tNumber of Terms:"; cin>>numberofterms; cout<<"\nThe geometric series is: \n"; newcommonratio=commonratio; cout<<start<<" "; for(i=2; i<numberofterms; i++) { cout<<calculation(start, newcommonratio, numberofterms)<<" "; newcommonratio=pow(commonratio,i); } } float Geometricseries::calculation(float start, float newcommonratio, int numberofterms) { return start*newcommonratio; } int main() { Geometricseries G; G.userinput(); G.calculation(G.start, G.commonratio, G.numberofterms); } Write an object oriented program for the Arithmetic series. #include<iostream> #include<cmath> using namespace::std; class Arithmeticseries { public: void userinput(); float calculation(float, float, int); float start, commondifference; int numberofterms, position; }; void Arithmeticseries::userinput() { cout<<"\nPlease enter the start Number: "; cin>>start; cout<<"\n\t\tCommon difference:"; cin>>commondifference; cout<<"\n\t\tNumber of Terms:"; cin>>numberofterms; cout<<"\nThe Arithmetic series is: \n"; for(position=1; position<=numberofterms; position++) { cout<<calculation(start, commondifference, position)<<" "; } } float Arithmeticseries::calculation(float start, float commondifference, int position) { return (start +(position -1)*commondifference); } int main() { Arithmeticseries A; A.userinput(); A.calculation(A.start, A.commondifference, A.position); return 0; }