You are on page 1of 15

GREENFIELDS PUBLIC SCHOOL

COMPUTER SCIENCE PROJECT


ON

“2D ARRAY”
Submitted in partial fulfillment of the requirements

For

CLASS XI

Submitted to:
Department of Computer Science

Submitted by:

KUSHAL TYAGI
XI C5
Roll no: 4829
ACKNOWLEDGEMENT

I wish to express my deep gratitude and sincere thanks to Principal, Dr. S.k.
Sharma for his encouragement and for all the facilities that he provided for this
project work. I sincerely appreciate his magnanimity by taking me into his fold for
which I shall remain indebted to him.

I extend my hearty thanks to Mrs. Sarita Verma, my computer science teacher,


who guided me to the successful completion of this project. I take this
opportunity to express my deep sense of gratitude for her invaluable guidance,
constant encouragement, constructive comments, sympathetic attitude and
immense motivation, which has sustained my efforts at all stages of this project
work.

I can’t forget to offer my sincere thanks to my classmates who helped me to carry


out this project work successfully & for their valuable advice & support, which I
received from them time to time.

Kushal Tyagi

CERTIFICATE
This is to certify that this project report “2D Array”,

Is the bonafide work of “Kushal Tyagi” Roll No: __4829__ of class


XI for the year 2017-18. He has carried out the project work under my
Supervisions.

Mrs. SARITA VERMA

P.G.T. (Computer Science)

INDEX

 Introduction
 Source Code
 Output
 Bibliography

INTRODUCTION

This project is about a 2D ARRAY.


Menu driven program of 2D array used as an argument to
a function -

DATA
1. Alternative element
2. Diagonals print
3. Swap 1st and last column
4. Reverse each row of an array
5. Quit

SOURCE CODE
//---------Menu driven program of 2D Array--------

// Developed by Kushal Tyagi


// XI C5
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>

void display(int x[][50],int r,int c)


{ for(int i=0;i<r;i++)
{
cout<<"\n";
for(int j=0;j<c;j++)
cout<<" "<<x[i][j];
}
}

void alt(int x[][50],int r,int c)


{ cout<<"\nAlternate elements : ";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
if((i+j)%2==0)
cout<<" "<<x[i][j];
}
}

void diag(int x[][50],int r,int c)


{ int i,j;
cout<<"\nFirst Diagonal : ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
if(i==j)
cout<<" "<<x[i][j];
}
cout<<"\nSecond Diagonal : ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
if(i+j==r-1)
cout<<" "<<x[i][j];
}
}
void change_col(int x[][50],int r,int c)
{ cout<<"\nChanged columns : ";
int i=0,j=c-1,k,temp;
for(k=0;k<r;k++)
{
temp=x[k][i];
x[k][i]=x[k][j];
x[k][j]=temp;
}
}
void reverse(int x[][50],int r,int c)
{
cout<<"\n\nReverse matrix rows : ";
for(int i=0;i<r;i++)
{ cout<<"\n";
for(int j=c-1;j>=0;j--)
cout<<" "<<x[i][j];
}
}

void main()
{ int a[50][50],i,j,r,c,ch,y,Y;
char chh;
clrscr();
do
{
cout<<”\n ____________________________ “;
cout<<”\n--------Menu driven program of 2D Array---------“;
cout<<”\n ____________________________ “;
cout<<"\n Enter no of rows = ";
cin>>r;
cout<<"\n Enter no of columns = ";
cin>>c;

for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
cout<<"\nEnter no = ";
cin>>a[i][j];
}
for(i=0;i<r;i++)
{
cout<<"\n";
for(j=0;j<c;j++)
cout<<" "<<a[i][j];
}
cout<<”\n _____________________________ “;
cout<<"\n-------Menu Driven program of 2D Array------- ";
cout<<”\n _____________________________ “;
cout<<"\n\n 1.Alternative Elements \n 2.Diagonals print \n 3.Swap 1st
and last column \n 4.Reverse each row of an array \n 5. Quit ";
cout<<"\n\n Enter your choice = ";
cin>>ch;

if(ch==1)
{ display(a,r,c);
alt(a,r,c);
}
else if(ch==2)
{ display(a,r,c);
diag(a,r,c);
}
else if(ch==3)
{ display(a,r,c);
change_col(a,r,c);
cout<<"\n";
display(a,r,c);
}
else if(ch==4)
{ display(a,r,c);
reverse(a,r,c);
}
else if(ch==5)
{
exit(0);
}

cout<<"\n\nDo you want to continue ? (y/n) : ";


cin>>chh;
}while(chh=='y' || chh=='Y');
getch();
}
Output
BIBLIOGRAPHY

 Retrieved from http://www.icbse.com


 About us: cppforschool. (2012, May).
Retrieved from
http://www.cppforschool.com
 S. Arora, Computer Science, C++.
Delhi: Dhanpat Rai &Co.

You might also like