Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:36:15+00:00 2026-05-25T18:36:15+00:00

I am working on a programming assignment in which we are making our own

  • 0

I am working on a programming assignment in which we are making our own BigNum class. One of the constructors needs to be set up so that it can take a number from a string (i.e. 342567) and reads it into an array. However if the number were 0000000342567 it would have to be able to skip over the 0s and just read 342567.

Where is what i have so far but am lost on trimming the 0s

BigNum::BigNum(const char strin[])
{
    size_t size = strlen(strin);
    positive = true;
    capacity = size;
    digits = new size_t[capacity];
    used=0;

    while(used<size)
    {
        if(strin[size - used -1] =='-')
        {
            positive = false;
            size --;
        }
        else if(strin[size - used -1] =='+')
        {
            size --;
        }
        else
        {
            digits[used] = strin[size - used -1] - '0';
            used++;
        }
    }
}

Here is the assignment description if it helps
http://csel.cs.colorado.edu/%7Eekwhite/CSCI2270Fall2011/hw2/Homework2.pdf

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:36:16+00:00Added an answer on May 25, 2026 at 6:36 pm

    Add this just before your while loop:

    for (int i=0; i < size; i++)
    {
        if (strin[i] >= '1' && strin[i] <= '9')
        {
            used = i;
            break;
        }
    }
    

    This way, your while loop begins reading the string only from the index where the number actually begins, skipping over all leading 0s.

    This should handle the leading sign as well:

    BigNum::BigNum(const char strin[])
    {
        size_t size = strlen(strin);
        positive = true;        
        used=0;
    
        if (strin[0] == '+' || strin[0] == '-')
        {
            //set positive or negative
            used++;
        }
        while (used < size)
        {
            if (strin[used] != '0')     
                break;
    
            used++; //used will only increment if above if condition failed.
        }
    
        int digitIndex = 0;
        digits = new size_t[size-used]; //create digits array here so it isn't larger than needed
    
        while(used<size)
        {        
             digits[digitIndex++] = strin[used++];      
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an assignment for my programming class but I've run into some
I am working on a programming assignment for my data structures class and we
I'm working on a game (C#) that uses a Robocode-like programming model: participants inherit
Are there actively working Mac OS X programming forums? Of course, SO is one
I'm working through the Stanford iPhone programming course online. The Presence app assignment pulls
I'm in the process of working on programming project that involves some pretty extensive
i'm working on a network programming assignment about writing a simple IM system (pretty
I'm currently working on a programming assignment for school. It's a simple text-based RPG.
I am currently working on a programming assignment. The assignment is to implement a
I'm a person with a non-programming background working on a web application that must

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.