CS201 Assignment No.2 Solution
Page 1 of 1 • Share
CS201 Assignment No.2 Solution
Assignment No. 02
Semester: Spring 2011
CS201: Introduction to Programming
Total Marks: 20
Due Date:02/05/2011
Instructions
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:
The assignment is submitted after due date.
The submitted assignment does not open or file is corrupt.
All types of plagiarism are strictly prohibited.
Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted. If you will submit code in .doc (Word document) you will get zero marks.
Objective
The objective of this assignment is to provide hands on experience of using
Basic concepts of arrays in C++ language
Conditional statements and loop structure of C++ language
Logical processing
Dealing with Data types
Writing and editing a C program
Guidelines
Code should be properly aligned and well commented.
Follow c/c++ rules while writing variables names, function names etc
Use only dev-C++ for this assignment.
Use appropriate c/c++ structure i.e. if-else, switch statement etc to get inputs from user.(Marks will be deducted if inappropriate structure will be used).
Assignment
Problem Statement: Sorting two matrices
You are required to write a program which takes two 3x3 matrix A and B containing 09 elements each and sort all these 18 elements in descending order and put it in one dimensional array and then display it.
Follow the following steps to code this program
1. Take two two-dimensional arrays as A[3][3]and B[3][3] and one-dimensional array C[] to keep the result.
2. Prompt the user to enter the elements of first matrix
3. Prompt the user to enter the elements of second matrix
4. Now take first element of first matrix and check in both matrix weather it is greatest or any other number is the greatest and put the greatest number at the first index of the one dimensional array. Follow this procedure for other elements and at the end one dimensional array would be in descending order
5. Display this one-Dimensional sorted array on the screen
Following is the sample program structure
2 3 5 2 8 7
A= 6 5 9 B= 0 1 1
1 0 2 4 7 9
Output should be like this
Please enter the Elements of First Matrix:
Please enter the Elements of second Matrix:
Sorted Values from Both the Matrices are:
-----------------------------------------------------------------
9 9 8 7 7 6 5 5 4 3 2 2 2 1 1 1 0 0
-----------------------------------------------------------------
Note:
Your assignment must be uploaded/submitted on or before May 2nd, 2011. Make it sure to submit only Cpp file of your Assignment. Assignment in notepad format or MS Word format will not be accepted.
Semester: Spring 2011
CS201: Introduction to Programming
Total Marks: 20
Due Date:02/05/2011
Instructions
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:
The assignment is submitted after due date.
The submitted assignment does not open or file is corrupt.
All types of plagiarism are strictly prohibited.
Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted. If you will submit code in .doc (Word document) you will get zero marks.
Objective
The objective of this assignment is to provide hands on experience of using
Basic concepts of arrays in C++ language
Conditional statements and loop structure of C++ language
Logical processing
Dealing with Data types
Writing and editing a C program
Guidelines
Code should be properly aligned and well commented.
Follow c/c++ rules while writing variables names, function names etc
Use only dev-C++ for this assignment.
Use appropriate c/c++ structure i.e. if-else, switch statement etc to get inputs from user.(Marks will be deducted if inappropriate structure will be used).
Assignment
Problem Statement: Sorting two matrices
You are required to write a program which takes two 3x3 matrix A and B containing 09 elements each and sort all these 18 elements in descending order and put it in one dimensional array and then display it.
Follow the following steps to code this program
1. Take two two-dimensional arrays as A[3][3]and B[3][3] and one-dimensional array C[] to keep the result.
2. Prompt the user to enter the elements of first matrix
3. Prompt the user to enter the elements of second matrix
4. Now take first element of first matrix and check in both matrix weather it is greatest or any other number is the greatest and put the greatest number at the first index of the one dimensional array. Follow this procedure for other elements and at the end one dimensional array would be in descending order
5. Display this one-Dimensional sorted array on the screen
Following is the sample program structure
2 3 5 2 8 7
A= 6 5 9 B= 0 1 1
1 0 2 4 7 9
Output should be like this
Please enter the Elements of First Matrix:
Please enter the Elements of second Matrix:
Sorted Values from Both the Matrices are:
-----------------------------------------------------------------
9 9 8 7 7 6 5 5 4 3 2 2 2 1 1 1 0 0
-----------------------------------------------------------------
Note:
Your assignment must be uploaded/submitted on or before May 2nd, 2011. Make it sure to submit only Cpp file of your Assignment. Assignment in notepad format or MS Word format will not be accepted.
Diya- Monstars
-
Posts : 364
Join date : 2011-02-08
Age : 33
Character sheet
Experience:
(10/500)
Re: CS201 Assignment No.2 Solution
plzz anybody help me... [You must be registered and logged in to see this image.]
Diya- Monstars
-
Posts : 364
Join date : 2011-02-08
Age : 33
Character sheet
Experience:
(10/500)
Re: CS201 Assignment No.2 Solution
I will try to give you the exact solution.. [You must be registered and logged in to see this image.]
munaza- Monstars
-
Posts : 385
Join date : 2011-02-24
Age : 36
Character sheet
Experience:
(500/500)
Re: CS201 Assignment No.2 Solution
thankx munaza [You must be registered and logged in to see this image.]
Diya- Monstars
-
Posts : 364
Join date : 2011-02-08
Age : 33
Character sheet
Experience:
(10/500)
Re: CS201 Assignment No.2 Solution
Check The Solution:
======
[You must be registered and logged in to see this image.]
#include
#include
main()
{
int ary1[3][3],ary2[3][3],ary[18],index,temp,max;
cout<<"Please enter the Elements of First Matrix: ";
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
cin>>ary1[n][m];
}
}
cout<<"Please enter the Elements of second Matrix: ";
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
cin>>ary2[n][m];
}
}
//Copying first array into single dimenional array
index=0;
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
ary[index]=ary1[n][m];
index++;
}
}
//Copying second array into single dimenional array
index=9;
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
ary[index]=ary2[n][m];
index++;
}
}
// Here sorting the third array in which ary1 and ary2 are copped....
// This sorting method is bubble sorting method in decending order.
[You must be registered and logged in to see this image.]
for(int n=0;n<18;n++)
{
for(int m=n;m<18;m++)
{
if(ary[n]
temp=ary[n];
ary[n]=ary[m];
ary[m]=temp;
}
}
}
//Show arranged array in decending order
cout<<"Sorted Values from Both the Matrices are: "<
{
cout<
getch();
}
[You must be registered and logged in to see this image.]
=======
Another
=======:
[You must be registered and logged in to see this image.]
#include
#include
main()
{
int ary1[3][3],ary2[3][3],ary[18],index,temp,max;
cout<<"Please enter the Elements of First Matrix: ";
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
cin>>ary1[n][m];
}
}
cout<<"Please enter the Elements of second Matrix: ";
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
cin>>ary2[n][m];
}
}
//Copying first array into single dimenional array
index=0;
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
ary[index]=ary1[n][m];
index++;
}
}
//Copying second array into single dimenional array
index=9;
for(int n=0;n<3;n++)
{
for(int m=0;m<3;m++)
{
ary[index]=ary2[n][m];
index++;
}
}
// Here sorting the third array in which ary1 and ary2 are copped....
// This sorting method is bubble sorting method in decending order.
for(int n=0;n<18;n++)
{
for(int m=n;m<18;m++)
{
if(ary[n]
temp=ary[n];
ary[n]=ary[m];
ary[m]=temp;
}
}
}
//Show arranged array in decending order
cout<<"Sorted Values from Both the Matrices are: "<
{
cout<
getch();
}
[You must be registered and logged in to see this image.]
munaza- Monstars
-
Posts : 385
Join date : 2011-02-24
Age : 36
Character sheet
Experience:
(500/500)
Re: CS201 Assignment No.2 Solution
thnx dear [You must be registered and logged in to see this image.]
Diya- Monstars
-
Posts : 364
Join date : 2011-02-08
Age : 33
Character sheet
Experience:
(10/500)
Re: CS201 Assignment No.2 Solution
welcome diya [You must be registered and logged in to see this image.]
munaza- Monstars
-
Posts : 385
Join date : 2011-02-24
Age : 36
Character sheet
Experience:
(500/500)
Similar topics
» CS201 Assignment No. 3
» CS201 Assignment No. 4
» MGT101 Assignment 1 Solution
» MGT 431 Assignment No. 1 Solution
» ENG 301 Assignment No. 1 Solution
» CS201 Assignment No. 4
» MGT101 Assignment 1 Solution
» MGT 431 Assignment No. 1 Solution
» ENG 301 Assignment No. 1 Solution
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Yesterday at 12:21 pm by ali001
» Hemangiom'App
Tue Nov 05, 2024 11:25 am by ali001
» MindfulMe - Mental Health App
Mon Nov 04, 2024 10:50 am by ali001
» Learn Candlestick Patterns
Tue Oct 15, 2024 5:51 am by ali001
» Woh Pagal Si Episode 52 to 62 - Top Pakistani Drama
Sat Sep 21, 2024 6:26 pm by Mir Emmad Ali Khan Domki
» Nearu - share your socials
Sat Sep 21, 2024 1:12 pm by ali001
» Nightclub Tycoon: Idle Empire
Thu Sep 19, 2024 9:16 pm by ali001
» Carnivore - Meat Diet Recipes
Wed Sep 18, 2024 2:37 pm by ali001
» Eid Milad un Nabi Mubarak 2024 (Rabiʻ I 14, 1446 AH)
Tue Sep 17, 2024 3:44 pm by Mir Emmad Ali Khan Domki