Related questions
complex.h
#pragma once
#include <iostream>
#include "imaginary.h"
using namespace std;
class Complex {
private:
int real;
Imaginary imagine;
public:
//YOU: Implement all these functions
Complex(); //Default constructor
Complex(int new_real, Imaginary new_imagine); //Two parameter constructor
Complex operator+(const Complex &rhs) const;
Complex operator-(const Complex &rhs) const;
Complex operator*(const Complex &rhs) const;
bool operator==(const Complex &rhs) const;
Complex operator^(const int &exponent) const;
friend ostream& operator<<(ostream &lhs,const Complex& rhs);
friend istream& operator>>(istream &lhs,Complex& rhs);
};
complex.cc
#include <iostream>
#include "complex.h"
using namespace std;
//Class definition file for Complex
//YOU: Fill in all of these functions
//There are stubs (fake functions) in there now so that it will compile
//The stubs should be removed and replaced with your own code.
Complex::Complex() {
}
Complex::Complex(int new_real, Imaginary new_imagine) {
}
Complex Complex::operator+(const Complex &rhs) const {
}
Complex Complex::operator-(const Complex &rhs) const {
}
Complex Complex::operator*(const Complex &rhs) const {
}
bool Complex::operator==(const Complex &rhs) const {
}
Complex Complex::operator^(const int &exponent) const {
}
//This function should output 3+5i for Complex(3,5), etc.
ostream& operator<<(ostream &lhs,const Complex& rhs) {
//Output a Complex here
}
//This function should read in two ints, and construct a
// new Complex with those two ints
istream& operator>>(istream &lhs,Complex& rhs) {
//Read in a Complex here
}
imaginary.h
#pragma once
#include <iostream>
using namespace std;
class Imaginary {
private:
int coeff; //If 5, then means 5i
public:
Imaginary();
Imaginary(int new_coeff);
int get_coeff() const;
Imaginary operator+(const Imaginary& rhs) const; //This is a "constant method"
Imaginary operator-(const Imaginary& rhs) const;
int operator*(const Imaginary& rhs) const;
Imaginary operator*(const int& rhs) const;
Imaginary operator=(const int& rhs);
Imaginary operator=(const Imaginary& rhs);
bool operator==(const Imaginary& rhs) const;
friend ostream& operator<<(ostream& lhs, const Imaginary& rhs);
friend istream& operator>>(istream& lhs, Imaginary& rhs);
};
imaginary.cc
#include "imaginary.h"
#include <iomanip>
using namespace std;
//Sample Code - I have done the addition operator for you so you can see
//what a functioning operator should look like. Given this function below,
//in main() you could write the following code:
// Imaginary foo(3); //foo is 3i
// Imaginary bar(5); //bar is 5i
// foo = foo + bar; //foo will become 8i
//In the above example, this function would get called on foo, with
//bar being passed in as the parameter named rhs (right hand side).
Imaginary Imaginary::operator+(const Imaginary& rhs) const {
return Imaginary(coeff+rhs.coeff); //My coeff is 3; rhs.coeff is 5. So construct a new one with a coeff of 8.
}
//These you will need to implement yourself.
//They currently are just stub functions
Imaginary::Imaginary() { //Default cstor
//coeff = ??
}
Imaginary::Imaginary(int new_coeff) { //One parameter cstor
//coeff = ??
}
int Imaginary::get_coeff() const { //Get function
return 0; //Change this
}
Imaginary Imaginary::operator-(const Imaginary& rhs) const {
return Imaginary(coeff-rhs.coeff);
}
Imaginary Imaginary::operator*(const int& rhs) const {
//5i * 2 = 10i
}
int Imaginary::operator*(const Imaginary& rhs) const {
//i * i = -1
}
//This function is functional
Imaginary Imaginary::operator=(const Imaginary& rhs) {
coeff = rhs.coeff;
return rhs;
}
//This function is functional
Imaginary Imaginary::operator=(const int& rhs) {
coeff = rhs;
return Imaginary(rhs);
}
bool Imaginary::operator==(const Imaginary& rhs) const {
return (true);
}
//This function is done for you. It will allow you to cout variables of type Imaginary.
//For example, in main you could write:
// Imaginary foo(2);
// cout << foo << endl;
//And this would print out "2i"
ostream& operator<<(ostream& lhs, const Imaginary& rhs) {
lhs << showpos;
lhs << rhs.coeff << "i"; //Will echo +4i or +0i or -3i or whatever
lhs << noshowpos;
return lhs;
}
istream& operator>>(istream& lhs, Imaginary& rhs) {
int i;
lhs >> i;
rhs.coeff = i;
return lhs;
}
HELP ME WITH HOMEWORK I CONFUSE. THANK YOU SO MUCH C++
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 2 images
- C++arrow_forwardThe code is in C++arrow_forwardIn C++ Q1.) Write a Review class that has: • These private data members: • string user: ID of the user • string item: ID of the item • double paid: the price of the item that the user buys • double rating: the rating that the user gives to the item • string review: the review content that the user gives to the item • These public member functions: • A default constructor to set all instance variables to a default value • A parameterized constructor (i.e., a constructor with arguments) to set all instance variables • A method for getting/setting the instance variables. • A method for printing the Review's information.arrow_forward
- In C++arrow_forwardProgram: File GamePurse.h: class GamePurse { // data int purseAmount; public: // public functions GamePurse(int); void Win(int); void Loose(int); int GetAmount(); }; File GamePurse.cpp: #include "GamePurse.h" // constructor initilaizes the purseAmount variable GamePurse::GamePurse(int amount){ purseAmount = amount; } // function definations // add a winning amount to the purseAmount void GamePurse:: Win(int amount){ purseAmount+= amount; } // deduct an amount from the purseAmount. void GamePurse:: Loose(int amount){ purseAmount-= amount; } // return the value of purseAmount. int GamePurse::GetAmount(){ return purseAmount; } File main.cpp: // include necessary header files #include <stdlib.h> #include "GamePurse.h" #include<iostream> #include<time.h> using namespace std; int main(){ // create the object of GamePurse class GamePurse dice(100); int amt=1; // seed the random generator srand(time(0)); // to play the...arrow_forwarddo part 4 import java.util.*; // Car classclass Car{ private String name; // Variable to hold car name private String model; // Variable to hold car model // Default constructor Car(){ this.name = null; this.model = null; } // Parametrised constructor Car(String name, String model){ this.name = name; this.model = model; } // Function to get car name public String getName(){ return this.name; }} // Dealer classclass Dealer{ private Car[] arr; // Array holding car objects for a dealer private int count; // Variable to hold number of cars under a dealer // Default constructor Dealer(){ arr = new Car[50]; count=0; } // Function to add a car under a dealer public void addCar(Car obj){ this.arr[this.count] = obj; this.count++; } // Function to check if a car exists under a dealer or not public boolean contains(String name){...arrow_forward
- Please examine the C++ code and make corrections please. ##include<bits / stdc++.h> using namespace std; //employee class class Employee { private: //fields string name, address, phone; double payRate; public: //cosntructors Employee() {} Employee(string n, string a, double p, string ph) { name = n; address = a; payRate = p; phone = p; } //accessors string getName() { return name; } string getAddress() { return address; } string getPhone() { return phone; } double getPayRate() { return payRate; } //setters void setName(string n) { name = n; } void setAddress(string a) { address = a; } void setPhone(string ph) { phone = ph; } void setPayRate(double pr) { payRate = pr; } }; //employee directory class class EmployeeDirectory { private: //all employees are added into this vector vector<Employee> employees; public:...arrow_forwardC++ language (Composition problem) Given the following two classes A and B, where all member functions have been fully implemented inline. class A { public: void f(int arg) { data = arg; } int g() { return data; } private: int data; }; class B { public: A x; }; int main() { B obj; // ... write code here return 0; } a. Insert the code in the main() function that assigns integer value 99 to the "data" member of obj, which is a B class object). b.Write the code to display the value (i.e., 99) that has just been assigned to the obj. c. Note that only a single object obj of B class is declared. How many times are constructors called? If more than one constructor is called, in what order are they called?arrow_forwardC++ #include <iostream>using namespace std; //creating struct to hold //student name,age and letter gradestruct student{ //data members string name; int age; char grade;};int main(){ //declaring object for the struct student *k = new student; //filling it with data k->name = "Kate"; k->age=24; k->grade='B'; ///then printing student data cout<<"Name:"<<k->name<<endl; cout<<"Age:"<<k->age<<endl; cout<<"Grade:"<<k->grade<<endl; return 0;}arrow_forward
- C:/Users/r1821655/CLionProjects/untitled/sequence.cpp:48:5: error: return type specification for constructor invalidtemplate <class Item>class sequence{public:// TYPEDEFS and MEMBER SP2020typedef Item value_type;typedef std::size_t size_type;static const size_type CAPACITY = 10;// CONSTRUCTORsequence();// MODIFICATION MEMBER FUNCTIONSvoid start();void end();void advance();void move_back();void add(const value_type& entry);void remove_current();// CONSTANT MEMBER FUNCTIONSsize_type size() const;bool is_item() const;value_type current() const;private:value_type data[CAPACITY];size_type used;size_type current_index;};} 48 | void sequence<Item>::sequence() : used(0), current_index(0) { } | ^~~~ line 47 template<class Item> line 48 void sequence<Item>::sequence() : used(0), current_index(0) { }arrow_forwardSolve the questionarrow_forwardQ2: Write a c++ program that implements the following UML diagram including functions and constructors' definitions. In addition to the user program code that declares object for each class and show how the derived class object uses the base class members. OOPCourse Student ID: int Grades[5]: int + setgrades(int arr[], int ): void + setID(int): int + setage(int): double + print():void + age:int + OOPstudent() OOPCourse OOPLAB OOPLab Reports[4]: int + setmarks(int arr[), int ): void + print():void + OOPLab()arrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY