Sponsored Links


Results 1 to 6 of 6

Thread: CS201 Introduction to Programming Fall 2010 second assignment solution

  1. #1
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,239

    Plurk 32 CS201 Introduction to Programming Fall 2010 second assignment solution

    Sponsored Links1


    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 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”.
    • 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
    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


    Solution will be update soon.


  2. #2
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    #include<iostream.h>
    #include<stdio.h>
    #include<conio.h>

    int main()
    {

    clrscr();
    int IndexA[10] = {0,0,0,0,0,0,0,0,0,0};
    int IndexB[10] = {0,0,0,0,0,0,0,0,0,0};

    cout<<"You Are Requested To Enter Values in Arrays "<<endl;
    cout<<"you should enter values between 1 & 20 "<<endl;
    cout<<"Enter Value In First Array"<<endl;
    for(int x=0 ; x<10 ; x++)
    {
    cout<<"Enter Value at - "<<x+1<<" - location - ";
    cin>>IndexA[x];
    if(IndexA[x] < 0 )
    {
    cout<<"please eneter the value between 1 & 20";
    cin>>IndexA[x];
    }
    else if(IndexA[x] >20)
    {
    cout<<"please eneter the value between 1 & 20";
    cin>>IndexA[x];
    }
    }
    clrscr();
    cout<<"enter Value In Second Array"<<endl;
    for(x=0 ; x<10 ; x++)
    {
    cout<<"Enter Value at - "<<x<<" - location - ";
    cin>>IndexB[x];
    if(IndexB[x] < 0 )
    {
    cout<<"please eneter the value between 1 & 20";
    cin>>IndexB[x];
    }
    else if(IndexB[x] >20)
    {
    cout<<"please eneter the value between 1 & 20";
    cin>>IndexB[x];
    }
    }
    clrscr();
    cout<<"You have enter these values in Array"<<endl;
    for(x =0 ; x<10 ; x++)
    {
    cout<<"Ist Array at - "<<x+1<<" - " <<IndexA[x]<<"| 2nd Array - " <<IndexB[x]<<endl;
    }

    //int IndexC[10] = {0,0,0,0,0,0,0,0,0,0};
    for(x =0 ; x <10 ;x++)
    {
    if(IndexA[x] == IndexB[x])
    {
    cout<<"Values Are Same At Index - "<<x+1<<"Where Value Is = "<<IndexA[x]<<endl;
    }
    }

    return 0;
    }



    Solovd By Aatish...

  3. #3

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    5
    Xpert why it does not compile..........when i click RUN it gives message that "source file not compile"

    Sponsored Links

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    4
    After compiling, I found 4 errors. How can I rectify them?

  6. #6
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,239
    well this should be completed by you. i just can offer help. i guess a person who is studying cs201 should remove the errors by him/her self. so i hope you will try and remove the errors and will post the correct error free code down this post.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 01-26-2012, 04:33 PM
  2. Replies: 63
    Last Post: 01-12-2011, 02:52 AM
  3. CS201 Introduction to Programming fall 2010 announcement
    By IQ-test in forum MCQ's & Quiz Discussion
    Replies: 0
    Last Post: 11-22-2010, 04:37 PM
  4. Replies: 13
    Last Post: 11-07-2010, 04:10 AM
  5. Replies: 0
    Last Post: 05-16-2010, 05:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft