0% found this document useful (0 votes)
19 views6 pages

Nashra Mukhtar

Uploaded by

Masood Mughal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

Nashra Mukhtar

Uploaded by

Masood Mughal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Rahima Qamar

2125165042
1. Storing and displaying values in a 2D array
#include<iostream>
using namespace std;
class Array{
private:
int arr[2][3];
public:
void input(){
cout<<"Enter values in array"<<endl;
for(int i=0; i<=1; i++){
for(int j=0; j<=2; j++){
cin>>arr[i][j];
}
}
}
void output(){
for(int i=0; i<=1; i++){
for(int j=0; j<=2; j++){
cout<<arr[i][j];
}
cout<<endl;
}
}
};
main(){
Array a;
a.input();
a.output();
}
2. Storing and displaying values till R rows and C columns in a 2D array
#include<iostream>
using namespace std;
class Array{
private:
int arr[2][3];
int r;
int c;
public:
void input(){
cout<<"Enter number of rows"<<endl;
cin>>r;
cout<<"Enter number of columns"<<endl;
cin>>c;
cout<<"Enter values in array"<<endl;
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cin>>arr[i][j];
}
}
}
void output(){
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cout<<arr[i][j];
}
cout<<endl;
}
}
};
main(){
Array a;
a.input();
a.output();
}
3. Transpose ofa 2D array
#include<iostream>
using namespace std;
class TransposeArray{
private:
int arr[2][3];
int r;
int c;
public:
void input(){
cout<<"Enter number of rows"<<endl;
cin>>r;
cout<<"Enter number of columns"<<endl;
cin>>c;
cout<<"Enter values in array"<<endl;
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cin>>arr[i][j];
}
}
}
void output(){
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cout<<arr[i][j];
}
cout<<endl;
}
}
void transpose(){
for(int i=r-1; i>=0; i--){
for(int j=c-1; j>=0; j--){
cout<<arr[i][j];
}
cout<<endl;
}
}
};
main(){
TransposeArray a;
a.input();
a.output();
a.transpose();
}
4. Push and Pop functions in Stack
#include<iostream>
using namespace std;
class PushPop{
private:
int stk[5]={3,6,5,8};
int top = 3;
public:
void push(){
int a=7;
if(top>4)
cout<<"Overflow"<<endl;
else{
top++;
stk[top]=a;
}
}
void pop(){
if(top<0)
cout<<"under flow ";
else
{
stk[top]=0;
top--;
}

}
void display(){
cout<<"values in stack = "<<endl;
for(int i=top; i>=0; i--)
cout<<stk[i]<<endl;
}
};
main(){
PushPop p;
int n;
cout<<"press 1 for push 2 for pop 3 for display "<<endl;
do
{
cin>>n;
switch (n)
{
case 1:
p.push();
break;
case 2:
p.pop();
break;
case 3:
p.display();
break;
default:
cout<<"invalid input";

}
}
while(n>=1);
}
5. Push and Pop functions in Stack
#include<iostream>
using namespace std;
class test
{
public:
int stk[10];
int top=-1;
void push()
{
if(top==9)
{
cout<<"over flow "<<endl;

}
else
{
for(int i=0;i<10;i++)
{
top++;
cout<<"enter value in stack = ";
cin>>stk[top];
}
}
}
void pop()
{
if(top<0)
{
cout<<"under flow ";

}
else
{
stk[top]=0;
top--;
}
}
void display()
{
if(top==-1)
cout<<"stack is empty :";
else
{
cout<<"even values in stack ="<<endl;
for(int i=top;i>=0;i--)
{
if(stk[i]%2==0)
cout<<stk[i]<<endl;
}
}
}
};
int main()
{
test t;
t.push();
t.pop();
t.display();
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy