Sie sind auf Seite 1von 8

http://vujannat.ning.

com/
Best Website TO Help VU Students
Assignment No. 2 Total Marks: 20
Semester: Fall 2010
CS201: Introduction to Programming Due Date: 22nd
November, 2010

Instructions:
Please read the following instructions carefully before submitting your
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 any other file
format like .doc or .txt etc. you will get zero marks.

Objective
The objective of this assignment is to provide hands on experience of using

 Basic concepts of C/C++ language and Programming


 Writing, Compiling and Executing a C program
 Conditional statements and Loops
 Functions and Arrays in C language

Guidelines
 Code should be properly aligned and well commented.
 Follow C/C++ rules while writing variables names, function names
etc.
 Use only Dev-C++ IDE for this assignment.

Assignment

Problem Statement: Comparing two arrays for equality or matching indexes

You are required to write a program which will take input from user in two
integer arrays. The program should compare both arrays for checking if both
arrays are totally identical (Exactly same). If not, then program should
determine the matching indexes of both arrays. Matching indexes means that

http://vujannat.ning.com/
Best Website TO Help VU Students
http://vujannat.ning.com/
Best Website TO Help VU Students
first element of array1 should be equal to first element of array2 and so
on.

Example of two identical (Exactly same) arrays:

Array1 Array2
1 1
2 2
3 3
5 5
7 7
9 9
11 11
13 13
15 15
17 17

Example of two arrays with some matching elements:

Array1 Array2
1 7
2 9
3 3
5 4
7 6
9 8
11 11
13 15
8 8
17 17

Here elements on index 3, 7, 9, and 10 of both arrays are same.

Detailed Description:
The program should take 10 integer inputs from user in arrray1 and array2.
• After taking inputs in both arrays, you should pass both arrays to a
function named match.
• If both arrays are exactly same, the program should display a message
“Both arrays are identical”.
http://vujannat.ning.com/
Best Website TO Help VU Students
http://vujannat.ning.com/
Best Website TO Help VU Students
• If both arrays are not exactly same, then program should match the
indexes which have same elements in both arrays and display the
matching indexes.
• If there is no element matching in both arrays, the program should
display a message
“There is no matching element in both arrays”.
• Implementation regarding comparison of arrays and displaying message
should be inside the function match.

Sample Output for two exactly same arrays

Please enter 10 integers for array1:


Enter element 1 : 1
Enter element 2 : 3
Enter element 3 : 5
Enter element 4 : 7
Enter element 5 : 9
Enter element 6 : 11
Enter element 7 : 13
Enter element 8 : 15
Enter element 9 : 17
Enter element 10 : 19

Please enter 10 integers for array2:


Enter element 1 : 1
Enter element 2 : 3
Enter element 3 : 5
Enter element 4 : 7
Enter element 5 : 9
Enter element 6 : 11
Enter element 7 : 13
Enter element 8 : 15
Enter element 9 : 17
Enter element 10 : 19

Both arrays are identical

Sample Output for arrays with some matching indexes

Please enter 10 integers for array1:


Enter element 1 : 1
Enter element 2 : 3
Enter element 3 : 5

http://vujannat.ning.com/
Best Website TO Help VU Students
http://vujannat.ning.com/
Best Website TO Help VU Students
Enter element 4 : 7
Enter element 5 : 9
Enter element 6 : 11
Enter element 7 : 13
Enter element 8 : 15
Enter element 9 : 17
Enter element 10 : 19

Please enter 10 integers for array2:


Enter element 1 : 2
Enter element 2 : 4
Enter element 3 : 5
Enter element 4 : 6
Enter element 5 : 9
Enter element 6 : 12
Enter element 7 : 14
Enter element 8 : 16
Enter element 9 : 17
Enter element 10 : 20

Both arrays have same elements on


Index 3
Index 5
Index 9

Deadline:
Your Assignment solution must be submitted on or before November 22, 2010.

Solution::

#include <iostream>

http://vujannat.ning.com/
Best Website TO Help VU Students
http://vujannat.ning.com/
Best Website TO Help VU Students
using namespace std;

voidmain()

char grade; //char for storing individual grade;

int i=1; //counter for while loop

int Acounter=0; //counter for A grade

while (i<=10)

startwhile:

cout"Please Enter Grade of student "i" :"endl;

cin>>grade;

http://vujannat.ning.com/
Best Website TO Help VU Students
http://vujannat.ning.com/
Best Website TO Help VU Students
if (grade=='A')

Acounter=Acounter+1;

else if (grade!='B')

coutendl"Please Enter 'A' or 'B' grade only!"endlendl;

goto startwhile;

i=i+1;

coutendlendl"Total No. of A Grades: "Acounterendl;

if (Acounter<=2)

http://vujannat.ning.com/
Best Website TO Help VU Students
http://vujannat.ning.com/
Best Website TO Help VU Students
{

cout"Your class is Poor!";

else if (Acounter<=7)

cout"Your class is Good!";

else if (Acounter<=8)

cout"Your class is Brilliant!";

coutendlendl;

} //bye bye

http://vujannat.ning.com/
Best Website TO Help VU Students
http://vujannat.ning.com/
Best Website TO Help VU Students

http://vujannat.ning.com/
Best Website TO Help VU Students

Das könnte Ihnen auch gefallen