Question

Hi, could some one please help me to check and see if I did this snippet...

Hi, could some one please help me to check and see if I did this snippet of code correctly? And according to these instructions?

  1. Function definition for the Overloaded operator >> for cin
    1. Signature: friend istream &operator>>(istream &in, Complex &c)
    2. Reads in a double, then another double, then a character (for 'i').
    3. You are essentially reading in 3 things, but only 2 of those things (the first and second) will get stored in the real and imaginary data members. The third thing to read in is to get rid of the 'i' from the input stream

THIS IS WHAT I WROTE (MY SNIPPET FOR THIS). Will it do what the instructions ask?

class Complex{

public:

/* other code here, but not including for brevity - it all works fine */

friend istream &operator>>(istream &in, Complex &c){
     char imagI = 'i';
     input>>c.real>>c.imaginary>>imagI;
return input;
  }
  

private:

double real;  
double imaginary;   

};

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class Complex{
public:
/* other code here, but not including for brevity - it all works fine */

    friend istream &operator>>(istream &in, Complex &c){
        char imagI = 'i';
        in>>c.real>>c.imaginary>>imagI;
        return in; // use in instead of input here..
    }
private:
    double real;  
    double imaginary;   
};
Add a comment
Know the answer?
Add Answer to:
Hi, could some one please help me to check and see if I did this snippet...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------...

    NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------------------------------------------------- Tasks to complete: ---------------------------------------------------------------------------------------------------------------------------------------- given code: ----------------------------------------------------------------------------------------------------------------------------------------------- main.cpp #include <iostream> #include <iomanip> #include "fractionType.h" using namespace std; int main() { fractionType num1(5, 6); fractionType num2; fractionType num3; cout << fixed; cout << showpoint; cout << setprecision(2); cout << "Num1 = " << num1 << endl; cout << "Num2 = " << num2 << endl; cout << "Enter the fraction in the form a / b: "; cin >> num2; cout << endl; cout <<...

  • 12.24 HW2: Practice with Classes Objectives: Become familiar with developing a C++ class, to include developing:...

    12.24 HW2: Practice with Classes Objectives: Become familiar with developing a C++ class, to include developing: A constructor An multiplication operator A friend function (input operator) Introduce various C and C++ functions for parsing user input Assignment Details This assignment consists of 6 parts. Part 1: Using an IDE of your own choosing (Visual Studio is recommended), create a new project and copy the starter code ComplexNumber.h ComplexNumber.cpp and TestComplexNumber.cpp to this new project for developing and testing your solution....

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

  • This is my Final Multiple Choice section of my Final Exam Please answer ABCD and neatly...

    This is my Final Multiple Choice section of my Final Exam Please answer ABCD and neatly please and thank you and all questions are with microsoft visual studio c++. MULTIPLE CHOICE. Choose ONLY ONE alternative that best completes the statement or answers the question. 1) Which of the following statements are correct? 1) _______ A) char charArray[2][] = {{'a', 'b'}, {'c', 'd'}}; B) char charArray[2][2] = {{'a', 'b'}, {'c', 'd'}}; C) char charArray[][] = {{'a', 'b'}, {'c', 'd'}};D) char charArray[][]...

  • Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and...

    Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and user_main.cpp. The programming language is C++. I will provide the Sample Test Driver Code as well as the codes given so far in text below. Sample Testing Driver Code: cs52::FlashDrive empty; cs52::FlashDrive drive1(10, 0, false); cs52::FlashDrive drive2(20, 0, false); drive1.plugIn(); drive1.formatDrive(); drive1.writeData(5); drive1.pullOut(); drive2.plugIn(); drive2.formatDrive(); drive2.writeData(2); drive2.pullOut(); cs52::FlashDrive combined = drive1 + drive2; // std::cout << "this drive's filled to " << combined.getUsed( )...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • Hello, my name is Shady Slim. I understand you are going to help me figure out...

    Hello, my name is Shady Slim. I understand you are going to help me figure out my gross income for the year... whatever that means. It's been a busy year and I'm a busy man, so let me give you the lowdown on my life and you can do your thing I was unemployed at the beginning of the year and got $2,000 in unemployment compensation. I later got a job as a manager for Roca Cola. I earned $57,500...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT