Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Practice paper_Object_Oriented_Programming

Rating
-
Sold
-
Pages
70
Uploaded on
12-07-2023
Written in
2022/2023

Object_Oriented_Programming_Practice paper with answer and all type of question

Institution
Course

Content preview

[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]-[#]

========================================================================
// 1. Write a C++ program to find largest element in an array.
#include <iostream>
using namespace std;
int main()
{
int a[2],i,max;
cout << "enter the number";

for ( i = 0; i < 2; i++)
{
cin >> a[i];
}
max = a[0];
for ( i = 1; i < 2; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
cout << "Largest element in the array is: " << max << endl;
return 0;
}



========================================================================
// 10. Write a C++ program that will find transpose of a matrix.
#include <iostream>
using namespace std;
int main()
{
int mat[2][2],rows,cols;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;

cout << "Enter the elements of the matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> mat[i][j];
}
}
cout << "The transpose of the matrix is: " << endl;
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{

, cout << mat[j][i] << " ";
}
cout << endl;
}
return 0;
}



========================================================================
// 11. Write a C++ program that will find subtraction of an matrices.

#include<iostream>
using namespace std;
class sub2d
{
int a[2][2],b[2][2],c[2][2],i,j;
public:
void get()
{
cout<<"Enter 1st array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter 2nd array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}
}
void disp()
{
cout<<"1st array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"2nd array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<b[i][j]<<" ";
}

, cout<<endl;
}
}
void sub()
{
cout<<"Sub of a and b array is "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout << a[i][j]-b[i][j]<<" ";
//c[i][j]=a[i][j]-b[i][j];
}
cout<<endl;
}
}
};
int main()
{
sub2d o1;
o1.get();
o1.disp();
o1.sub();
}




========================================================================
// 12. Write a C++ program to find sum of all the diagonal elements of a
matrix.
#include <iostream>
using namespace std;
int main()
{
int a[2][2] rows, cols,diagonal_sum = 0;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;


cout << "Enter the elements of the matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cin >> a[i][j];

, }
}

for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (i == j)
{
diagonal_sum += a[i][j];
}
}
}
cout << "The sum of all diagonal elements is: " << diagonal_sum << endl;
return 0;
}



========================================================================
// 13. Write a C++ program that will find multiplication of two matrices.
#include<iostream>
using namespace std;
class mul2d
{
int a[2][2],b[2][2],c[2][2],i,j;
public:
void get()
{
cout<<"Enter 1st array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter 2nd array elements";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}
}
void disp()
{
cout<<"1st array elements are"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<" ";
}

Written for

Institution
Course

Document information

Uploaded on
July 12, 2023
Number of pages
70
Written in
2022/2023
Type
Class notes
Professor(s)
Riddhi kudal
Contains
All classes

Subjects

$16.19
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
parthpadhara

Get to know the seller

Seller avatar
parthpadhara Yale University
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
39
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions