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 8413665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:57:39+00:00 2026-06-10T00:57:39+00:00

I assigned myself some homework over the summer, and the project I am 98%

  • 0

I assigned myself some homework over the summer, and the project I am 98% finished with has come to a standstill due to this one problem.

I have a class called Mixed. It contains member data for a whole number, a numerator, and a denominator. I need to overload all of the common operators to allow multiplication, addition, comparison and streaming of objects of type Mixed. I have all the operators overloaded except for >> (the extraction operator).

All mixed numbers read in will be of format:
whole numerator/denominator

ex: 1 2/3, 0 7/8, -3 18/5, 0 -1/89

Header: friend istream& operator>> (istream &, Mixed);

CPP file: istream& operator>> (istream &in, Mixed m) {...}

For the assignment, I am limited to the iostream and iomanip libraries. My plan was to read in the values from the stream and assign them to temporary int variables (w, n, d) which I would then use with the Mixed constructor to create object m. Unfortunately, I cannot think of a way to separate the numerator and denominator. They are both ints, but they have a char (/) between them.

  • I cannot use getline() with its delimiter, because it assigns data to a char array, which I do not believe I can convert to an int without another library.
  • I cannot use a char array and then segment it for the same reason.
  • I cannot use a while loop with get() and peek() because, again, I do not think I will be able to convert a char array into an int.
  • I cannot use a string or c-string and then segment it because that requires external libraries.

Once again, I need to split a value like “22/34” into 22 and 34, using only iostream and iomanip. Is there some fairly obvious method I am overlooking? Is there a way to implicitly convert using pointers?

  • 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-06-10T00:57:40+00:00Added an answer on June 10, 2026 at 12:57 am

    You could first extract the nominator, then the separating character, and then the denominator.

    Example for illustration:

    istream& operator>> (istream &in, Mixed &m) {
        int num, denom;
        char separ;
    
        in >> num;
        in.get(separ);
        if (separ != '/')
          in.setstate(ios::failbit);
        in >> denom;
    
        if (in) {
          // All extraction worked
          m.numerator = num;
          m.denominator = denom;
        }
    
        return in;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a homework project I was assigned some time ago... I've been successful
As part of a project I have assigned myself as a way of improving
I wanted some input on an interesting problem I've been assigned. The task is
I'm teaching myself .NET c# through books and self-assigned projects for fun. I thought
It didn't have a project and I removed myself as the assignee, now I
I assigned a password to the root MySQL user in XAMPP some times ago.
I have assigned a custom data attribute to some circles added to the Raphael
Recently I just got assigned a project to develop a web application/site that uses
I am stuck with this, I have been putting myself through a crash course
I have this Problem and solving it is not the problem, more like what

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.