Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
Aim: To implement a program to allocate memory dynamically for 2 dimensional array (accept and print matrix) using pointers.
Code:
#include
class matrix
{
int **p,r,c,i,j;
public:
matrix(int,int);
~matrix();
void getdata();
void display();
};
matrix::matrix(int x,int y)
r=x;
c=y;
p=new int *[r];
for(i=0;i p[i]=new int [c]; } matrix::~matrix() { for(i=0;i delete p[i]; delete p; cout<<"\nMemory deallocated successfully\n"; } void matrix::getdata() { cout<<"\nEnter matrix values:\n"; for(i=0;i { cout<<"Enter values for row:"< for(j=0;j cin>>p[i][j]; } } void matrix::display() { cout<<"\nThe matrix is:\n"; for(i=0;i {; for(j=0;j cout< cout< } } void main() { int rows,cols; clrscr(); cout<<"Enter number of rows and columns for a matrix\n"; cout<<"Enter number of rows\n"; cin>>rows; cout<<"Enter number of columns\n"; cin>>cols; matrix A(rows,cols); A.getdata(); A.display(); getch(); } Output: Enter number of rows and columns for a matrix Enter number of rows 3 Enter number of columns 3 Enter the values of the matrix Enter values for row 1 1 2 3 Enter values for row 2 4 5 6 Enter values for row 3 7 8 9 The matrix is 1 2 3 4 5 6 7 8 9 Memory deallocated successfully
p[i]=new int [c];
}
matrix::~matrix()
for(i=0;i delete p[i]; delete p; cout<<"\nMemory deallocated successfully\n"; } void matrix::getdata() { cout<<"\nEnter matrix values:\n"; for(i=0;i { cout<<"Enter values for row:"< for(j=0;j cin>>p[i][j]; } } void matrix::display() { cout<<"\nThe matrix is:\n"; for(i=0;i {; for(j=0;j cout< cout< } } void main() { int rows,cols; clrscr(); cout<<"Enter number of rows and columns for a matrix\n"; cout<<"Enter number of rows\n"; cin>>rows; cout<<"Enter number of columns\n"; cin>>cols; matrix A(rows,cols); A.getdata(); A.display(); getch(); } Output: Enter number of rows and columns for a matrix Enter number of rows 3 Enter number of columns 3 Enter the values of the matrix Enter values for row 1 1 2 3 Enter values for row 2 4 5 6 Enter values for row 3 7 8 9 The matrix is 1 2 3 4 5 6 7 8 9 Memory deallocated successfully
delete p[i];
delete p;
cout<<"\nMemory deallocated successfully\n";
void matrix::getdata()
cout<<"\nEnter matrix values:\n";
for(i=0;i { cout<<"Enter values for row:"< for(j=0;j cin>>p[i][j]; } } void matrix::display() { cout<<"\nThe matrix is:\n"; for(i=0;i {; for(j=0;j cout< cout< } } void main() { int rows,cols; clrscr(); cout<<"Enter number of rows and columns for a matrix\n"; cout<<"Enter number of rows\n"; cin>>rows; cout<<"Enter number of columns\n"; cin>>cols; matrix A(rows,cols); A.getdata(); A.display(); getch(); } Output: Enter number of rows and columns for a matrix Enter number of rows 3 Enter number of columns 3 Enter the values of the matrix Enter values for row 1 1 2 3 Enter values for row 2 4 5 6 Enter values for row 3 7 8 9 The matrix is 1 2 3 4 5 6 7 8 9 Memory deallocated successfully
cout<<"Enter values for row:"<
for(j=0;j cin>>p[i][j]; } } void matrix::display() { cout<<"\nThe matrix is:\n"; for(i=0;i {; for(j=0;j cout< cout< } } void main() { int rows,cols; clrscr(); cout<<"Enter number of rows and columns for a matrix\n"; cout<<"Enter number of rows\n"; cin>>rows; cout<<"Enter number of columns\n"; cin>>cols; matrix A(rows,cols); A.getdata(); A.display(); getch(); } Output: Enter number of rows and columns for a matrix Enter number of rows 3 Enter number of columns 3 Enter the values of the matrix Enter values for row 1 1 2 3 Enter values for row 2 4 5 6 Enter values for row 3 7 8 9 The matrix is 1 2 3 4 5 6 7 8 9 Memory deallocated successfully
cin>>p[i][j];
void matrix::display()
cout<<"\nThe matrix is:\n";
for(i=0;i {; for(j=0;j cout< cout< } } void main() { int rows,cols; clrscr(); cout<<"Enter number of rows and columns for a matrix\n"; cout<<"Enter number of rows\n"; cin>>rows; cout<<"Enter number of columns\n"; cin>>cols; matrix A(rows,cols); A.getdata(); A.display(); getch(); } Output: Enter number of rows and columns for a matrix Enter number of rows 3 Enter number of columns 3 Enter the values of the matrix Enter values for row 1 1 2 3 Enter values for row 2 4 5 6 Enter values for row 3 7 8 9 The matrix is 1 2 3 4 5 6 7 8 9 Memory deallocated successfully
{;
for(j=0;j cout< cout< } } void main() { int rows,cols; clrscr(); cout<<"Enter number of rows and columns for a matrix\n"; cout<<"Enter number of rows\n"; cin>>rows; cout<<"Enter number of columns\n"; cin>>cols; matrix A(rows,cols); A.getdata(); A.display(); getch(); } Output: Enter number of rows and columns for a matrix Enter number of rows 3 Enter number of columns 3 Enter the values of the matrix Enter values for row 1 1 2 3 Enter values for row 2 4 5 6 Enter values for row 3 7 8 9 The matrix is 1 2 3 4 5 6 7 8 9 Memory deallocated successfully
cout<
cout< } } void main() { int rows,cols; clrscr(); cout<<"Enter number of rows and columns for a matrix\n"; cout<<"Enter number of rows\n"; cin>>rows; cout<<"Enter number of columns\n"; cin>>cols; matrix A(rows,cols); A.getdata(); A.display(); getch(); } Output: Enter number of rows and columns for a matrix Enter number of rows 3 Enter number of columns 3 Enter the values of the matrix Enter values for row 1 1 2 3 Enter values for row 2 4 5 6 Enter values for row 3 7 8 9 The matrix is 1 2 3 4 5 6 7 8 9 Memory deallocated successfully
void main()
int rows,cols;
clrscr();
cout<<"Enter number of rows and columns for a matrix\n";
cout<<"Enter number of rows\n";
cin>>rows;
cout<<"Enter number of columns\n";
cin>>cols;
matrix A(rows,cols);
A.getdata();
A.display();
getch();
Output:
Enter number of rows and columns for a matrix
Enter number of rows
3
Enter number of columns
Enter the values of the matrix
Enter values for row 1
1 2 3
Enter values for row 2
4 5 6
Enter values for row 3
7 8 9
The matrix is
Memory deallocated successfully
how to write
genetic disorder
Write a ''C'' program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.
(a) Write a recursive procedure (digits n) that computes the number of digits in the integer n using a linear recursive process. For example, (digits 42) should return 2 and (digit
Ask question #Minimum 100 what is friend function is used in c++
Define the Category of Function? A function, depending on whether arguments or parameters are present or not and whether a value returned or not, may belong to one of the foll
Describe the “placement new" and why would I use it?
source code for padovan string
wap to calculatethe volume of cone,cylinderand sphere
wap to print padovan string in c
Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!
whatsapp: +1-415-670-9521
Phone: +1-415-670-9521
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd