Related questions
Concept explainers
Please help! The goal of this project is to write the interface and implementation for the complex number class. THE INSTRUCTIONS ARE BELOW (IN BOLD):
Please complete the below STARTER functions (some variables need to be defined) ALL BOLDED SECTIONS CORRESPOND WITH ONE ANOTHER:
complex.h:
/**
* public interface for the complex number class.
* </pre>
*/
#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
using namespace std;
/* YOUR TASK HERE IS TO GIVE THE COMPLETE DEFINITION OF
THE class Complex. BE SURE TO INCLUDE A DESCRIPTION OF EACH OF THE FUNCTIONS.
YOU WILL PROVIDE ONLY THE PUBLIC INTERFACE OF THE MEMBER
AND FRIEND FUNCTIONS, NOT THEIR DEFINITIONS.
THE MEMBER AND FRIEND FUNCTIONS WILL BE DEFINED IN THE
IMPLEMENTATION FILE.
DEFINE THE CLASS BELOW.
*/
#endif
complex.cpp:
/**
* Implementation for the complex class
* </pre>
*/
#include <cmath>
#include <cstdlib>
#include "complex.h"
/* SOME FUNCTION HAVE BEEN IMPLEMENTED. IMPLEMENT
ALL OTHER FUNCTIONS.
*/
Complex::Complex()
{
real = 0.0;
imag = 0.0;
}
double Complex::getReal() const
{
return real;
}
Complex Complex::conjugate() const
{
return Complex(real,-imag);
}
Complex operator +(const Complex& z1, const Complex& z2)
{
return Complex(z1.real+z2.real,z1.imag+z2.imag);
}
ostream& operator<<(ostream& out, const Complex& z)
{
if (z.real == 0 && z.imag == 0)
{
out<<"0";
return out;
}
if (z.real == 0)
{
if (z.imag < 0)
{
if (z.imag != -1)
out<<z.imag<<"i";
else
out<<"-i";
}
else
{
if (z.imag != 1)
out<<z.imag<<"i";
else
out<<"i";
}
return out;
}
if (z.imag == 0)
{
out<<z.real;
return out;
}
out <<z.real;
if (z.imag < 0)
{
if (z.imag != -1)
out<<z.imag<<"i";
else
out<<"-i";
}
else
{
if (z.imag != 1)
out<<"+"<<z.imag<<"i";
else
out<<"+i";
}
return out;
}
completest.cpp
/**
* A program to test the complex class implementation
*/
#include <iostream>
#include "complex.h"
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
Complex z0(3.6,4.8);
Complex z1(4,-2);
Complex z2(-4,2);
Complex z3(-4,-3);
Complex z4(3,-4);
Complex z5;
Complex z6;
Complex z7;
double ang;
cout<<"z0 = "<<z0<<" and re(z0) = "<<z0.getReal()<<" and "
<<"im(z0) = "<<z0.getImag()<<"."<<endl;
cout<<"z1 = "<<z1<<endl;
cout<<"z2 = "<<z2<<endl;
cout<<"z3 = "<<z3<<endl;
cout<<"z4 = "<<z4<<endl;
cout<<"z2 x z3 = "<<z2*z3<<endl;
cout<<"z1 + z2 = "<<z1+z2<<endl;
cout<<"z3 = "<<z3<<endl;
cout<<"z4 = "<<z4<<endl;
cout<<"z3-z4 = "<<z3-z4<<endl;
cout<<"((z2+z3)x(z3-z4)) = ";
cout<<(z2+z3)*(z3-z4)<<endl;
cout<<"z1^3 = "<<pow(z1,3)<<endl;
cout<<"1/z2^2 = "<<pow(z2,-2)<<endl;
cout<<"z3^0 = "<<pow(z3,0)<<endl;
try
{
cout<<"((z2+z3)x(z3-z4))/z3 = ";
z6 = ((z2+z3)*(z3-z4))/z3;
cout<<z6<<endl;
cout<<"z3 / z4 = "<<(z3/z4)<<endl;
cout<<"Conj(z4) = "<<z4.conjugate()<<endl;
cout<<"The real part of the conjugate of z4 is "<<(z4.conjugate()).getReal()<<endl;
cout<<"The imaginary part of the conjugate of z4 is "<<(z4.conjugate()).getImag()<<endl;
cout<<"The argument of the conjugate of z4 is "<<(z4.conjugate()).argument()<<"."<<endl;
cout<<"The modulus of the conjugate of z4 is "<<(z4.conjugate()).modulus()<<"."<<endl;
cout<<"(z3*conj(z4))/(z4*conj(z4))= ";
cout<<(z3*z4.conjugate())/(z4*z4.conjugate())<<endl;
/* Add statement here to compute ((z1-z2).(z3/z4))/(z4/z3)
and print the result:*/
ang = (z1+z2).argument();
cout<<"angle = "<<ang<<endl;
/* Put a comment here explaining what happened and why?
*/
}
catch(int e)
{
if (e == -1)
cerr<<"DivideByZero Exception in / operator"<<endl;
else if (e == -2)
cerr<<"DivideByZero Exception in argument function"<<endl;
}
return 0;
}
Step by stepSolved in 4 steps
- This is my code in c++. When the chosen class is full I want the code to automatically assign it to the next available class (Economy). Also when the economy class is full I want the code to automatically assign it to the next available First Class seat. #include <iostream> using namespace std; void ShowInfo(); void printInfo(char input[9][4]); void DesiredRow(int row[2], char seat); int main () { int ROW = 9, SEATS = 4; int row[9]; char airchar[9][4]; char seat; string answer; string ticket; string name; string newanswer; for (int i = 0; i < ROW; i++) { for (int j = 0; j < SEATS; j++) { airchar[i][j] = '*'; } } cout << "Please enter your full name: " << endl; getline(cin, name); while ("Yes") { cout << " Do you wish to book a seat: " << endl; cout << " Yes or No: " << endl; cin >> answer;...arrow_forwardIn C++ , Write a program that creates an EvenNumber object for value 16 and invokes the getNext() and getPrevious() functions to obtain and displays these numbers. The program must contain the following, **please also implement the class A data field value of the int type that represents the integer value stored in the object. A no-arg constructor that creates an EvenNumber object for the value 0. A constructor that constructs an EvenNumber object with the specified value. A function named getValue() to return an int value for this object. A function named getNext() to return an EvenNumber object that represents the next even number after the current even number in this object. A function named getPrevious() to return an EvenNumber object that represents the previous even number before the current even number in this object.arrow_forwardPlease create a code on c++ for this description. Include a flow chart aswell. Components: ●くろまる Multiple files with classes organized. A well organized solution is critical. ●くろまる Implemented the above described functionality. ●くろまる Created a main function to showcase the different functions that were implemented along with a guide explaining what you are showing.arrow_forward
- Write a C#program that uses a class called ClassRegistration as outlined below: The ClassRegistration class is responsible for keeping track of the student id numbers for students that register for a particular class. Each class has a maximum number of students that it can accommodate. Responsibilities of the ClassRegistration class: It is responsible for storing the student id numbers for a particular class (in an array of integers) It is responsible for adding new student id numbers to this list (returns boolean) It is responsible for checking if a student id is in the list (returns a boolean) It is responsible for getting a list of all students in the class (returns a string). It is responsible for returning the number of students registered for the class (returns an integer) It is responsible for returning the maximum number of students the class is allowed (returns an integer) It is responsible for returning the name of the class. (returns a string) ClassRegistration -...arrow_forwardFill in the blanksarrow_forwardThis is my code in c++. When the chosen class is full I want the code to automatically assign it to the next available class (Economy). Also when the economy class is full I want the code to automatically assign it to the next available First Class seat. #include <iostream> using namespace std; void ShowInfo(); void printInfo(char input[9][4]); void DesiredRow(int row[2], char seat); int main () { int ROW = 9, SEATS = 4; int row[9]; char airchar[9][4]; char seat; string answer; string ticket; string name; string newanswer; for (int i = 0; i < ROW; i++) { for (int j = 0; j < SEATS; j++) { airchar[i][j] = '*'; } } cout << "Please enter your full name: " << endl; getline(cin, name); while ("Yes") { cout << " Do you wish to book a seat: " << endl; cout << " Yes or No: " << endl; cin >> answer;...arrow_forward
- Written in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forwardJava programming Please type the code Please use class Homework as a class function For this problem set, you will submit a single java file named Homework.java. You are supposed to add the functions described below to your Homework class. The functional signatures of the functions you create must exactly match the signatures in the problem titles. You are not allowed to use any 3rd party libraries in the homework assignment nor are you allowed to use any dependencies from the java.util package besides the Pattern Class. When you have completed your homework, upload the Homework.java file to Grader Than. All tests will timeout and fail if your code takes longer than 10 seconds to complete. privateFunction() This is a private non-static function that takes no arguments and returns an integer. You don't need to put any code in this function, you may leave the function's code empty. Don't overthink this problem. This is to test your knowledge on how to create a non-static private...arrow_forwardUsing C++ Without Using linked lists: Create a class AccessPoint with the following: x - a double representing the x coordinate y - a double representing the y coordinate range - an integer representing the coverage radius status - On or Off Add constructors. The default constructor should create an access point object at position (0.0, 0.0), coverage radius 0, and Off. Add accessor and mutator functions: getX, getY, getRange, getStatus, setX, setY, setRange and setStatus. Add a set function that sets the location coordinates and the range. Add the following member functions: move and coverageArea. Add a function overLap that checks if two access points overlap their coverage and returns true if they do. Add a function signalStrength that returns the wireless signal strength as a percentage. The signal strength decreases as one moves away from the access point location. Represent this with bars like, IIIII. Each bar can represent 20% Test your class by writing a main function that...arrow_forward
- Write a C# program that uses a class called ClassRegistration as outlined below: The ClassRegistration class is responsible for keeping track of the student id numbers for students that register for a particular class. Each class has a maximum number of students that it can accommodate. Responsibilities of the ClassRegistration class: It is responsible for storing the student id numbers for a particular class (in an array of integers) It is responsible for adding new student id numbers to this list (returns boolean) It is responsible for checking if a student id is in the list (returns a boolean) It is responsible for getting a list of all students in the class (returns a string). It is responsible for returning the number of students registered for the class (returns an integer) It is responsible for returning the maximum number of students the class is allowed (returns an integer) It is responsible for returning the name of the class. (returns a string)arrow_forwardCan you please help with this Use the provided template below BASE_YEAR = 1903 #***************************************************************# Function: main# # Description: The main function of the program## Parameters: None## Returns: Nothing ##**************************************************************def main():# Local dictionary variablesyear_dict = {}count_dict = {}developerInfo()# Open the file for readinginput_file = open('Program11.txt', 'r') # End of the main function #*********************************************## Function: # # Description: ## Parameters:## Returns: ##*****************************************def showResults(year_dict, count_dict):# Receive user inputyear = int(input('Enter a year in the range 1903-2018: ')) # Print resultsif year == 1904 or year == 1994:print("The world series wasn't played in the year", year)elif year < 1903 or year > 2018:print('The data for the year', year, \'is not included in our database.')else:winner = year_dict[year]wins...arrow_forwardEach function inside the class A(n)_ is a virtual function. Provide your thoughts by filling in the blanks.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education