CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Jul 2010
    Posts
    75

    Need Help With The Array

    hello guys can u tell me how i will solve this question with array
    i answer it but i guess there is alot of problems and it doesnt work ,

    THE QUESTION IS
    ==============
    Write a function named insertzeros that takes as parameters : an array of integers , number of elements in the array which is passed by reference , a position in the array pos , an integer NB ( the number of zeros to be inserted ) , and a constant array SIZE ( maximum size ) . The function should insert NB zeros starting from pos.
    the function prototype is :

    void insertzeros ( int arr [], int & length , int pos , int NB , const int SIZE );
    ==============


    PHP Code:


    # include <iostream>
    using namespace std;
    void insertzerosint arr [],int length ,int pos int NB, const int SIZE)
    {
    int i;
    for(
    int j=0j<NBj++)
    for ( 
    i=length-1i>posi--)
    arr [i+1]=arr[i];
    length ++;
    for(
    int k=posk<NBk++)
    arr [k]=0;
    int main ()
    {
    int NB,pos,arr;
    cout << " Enter The Number Of Zeros " <<endl;
    cin >>NB;
    cout << " Enter The Position " <<endl;
    cin >>pos;
    cout << " Enter The Array Size "<<endl;
    for (
    int s=os<length+1s++)
    cin>>arr[];


    Last edited by jacksparrow; October 2nd, 2010 at 08:01 AM.

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Need Help With The Array

    [ Moved thread ]

    // Please use CODE tags to make code more readable.

  3. #3
    Join Date
    Jul 2010
    Posts
    75

    Re: Need Help With The Array

    ok sorry boss
    next time am gonna use it

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Need Help With The Array

    Quote Originally Posted by jacksparrow View Post
    ok sorry boss
    next time am gonna use it
    You can edit the previous post as well.

  5. #5
    Join Date
    Jul 2010
    Posts
    75

    Re: Need Help With The Array

    i edit the code ,,, why no one try to help me out in the answer... i thought it gonna be easy for the professionals

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Need Help With The Array

    Quote Originally Posted by jacksparrow View Post
    i edit the code ,,, why no one try to help me out in the answer... i thought it gonna be easy for the professionals
    Now go back and use proper indentation and line up the braces. Once you do that, your biggest initial problem should be obvious.

    Also, to get help, you need to be more specific than just saying it doesn't work. If there are compiler errors list them and tell us what line of code they're on.

  7. #7
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: Need Help With The Array

    Quote Originally Posted by jacksparrow View Post
    i edit the code ,,, why no one try to help me out in the answer... i thought it gonna be easy for the professionals
    Nothing is easy, don't ever take things for granted.

    Next, properly indent the code as it still is a bit messy to read.

    Third, when you compile this code, what's the first error message you see?

    Fourth and the biggest mystery is, where is your array??

  8. #8
    Join Date
    Jul 2010
    Posts
    75

    Re: Need Help With The Array

    Quote Originally Posted by potatoCode View Post
    Nothing is easy, don't ever take things for granted.

    Next, properly indent the code as it still is a bit messy to read.

    Third, when you compile this code, what's the first error message you see?

    Fourth and the biggest mystery is, where is your array??
    hello mate,, whats uP ?
    ok lets to about the array

    i should put it after using namespace right

    # include <iostream>
    using namespace std;
    int arr = 10;
    void insertzeros( int arr [],int & length ,int pos , int NB, const int SIZE)

  9. #9
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Need Help With The Array

    That's a single int. There's no array.

    There is a function parameter specified to be an array with the same name, but it's an unrelated variable.

  10. #10
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Question Re: Need Help With The Array

    That is a very strange assignment. What is length vs. SIZE? Does he want you to grow the array? What if the number of zeroes to insert plus the starting position puts you beyond the length or max size? I'd guess that length is the current amount of data that has been assigned and that SIZE is the actual size of the array, arr. Is that correct?

  11. #11
    Join Date
    Jul 2010
    Posts
    75

    Re: Need Help With The Array

    yeah it's really missed up assignment i have been given from my doctor , and i still couldnt answer it well.. anyway ur right he want me to put zeros in the start of pos and if there is no space in the length i have to make space and put zeros

  12. #12
    Join Date
    Jul 2010
    Posts
    75

    Re: Need Help With The Array

    i edited now the function and i think its correct , all i need to do now cout and cin



    PHP Code:
    void insertzeros (int arr[],int &length,int pos,int NB,const int SIZE)
    {
    if (
    length==SIZE)
    {
        
    cout<<"Sorry array is fall"<<endl;
    return;
    }

    for(
    int j=0;j<NB;j++)
    {

    for (
    int i=length;i>=pos;i--)
    {
    arr[i]=arr[i-1];
    }
    arr[i]=0;
    length++;


  13. #13
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Question Re: Need Help With The Array

    Quote Originally Posted by jacksparrow View Post
    i edited now the function and i think its correct , all i need to do now cout and cin



    PHP Code:
    void insertzeros (int arr[],int &length,int pos,int NB,const int SIZE)
    {
    if (
    length==SIZE)
    {
        
    cout<<"Sorry array is fall"<<endl;
    return;
    }

    for(
    int j=0;j<NB;j++)
    {

    for (
    int i=length;i>=pos;i--)
    {
    arr[i]=arr[i-1];
    }
    arr[i]=0;
    length++;

    Okaaaaaay.

    Well good luck with your program. I'm not sure what you are asking for at this point.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured