Read the following program project1.cpp carefully. Complete the missing code as indicated by the comments. Then compile, debug and test your program using the command lines below before your submission:
c++ -o project1 project1.cpp <enter>
./project1 n m k <enter>
Where n is the size of the stack, m is the modular of the real part and imagination part of a random complex number, and k is the number of elements displayed per line.
In the main function, you need to
// project1.cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Complex {// complex number class
float re;// real part
float im;// imagination part
public:
Complex(float r=0.0, float i=0.0){re=r; im=i;}// constructor
Complex(const Complex& c){re=c.re; im=c.im;}// copy constructor
void operator =(const Complex& c){re=c.re; im=c.im;}// assignment
Complex operator -()const{return Complex(-re, -im);}// unary negation
Complex operator +(const Complex&) const;// addition operator
Complex operator -(const Complex&) const;// subtraction operator
Complex operator *(const Complex&) const;// multiplication operator
Complex operator /(const Complex&) const;//division operator
friend ostream& operator <<(ostream&, const Complex&);// output operator
};
// overloaded addition operator, to be implemented
Complex Complex::operator +(const Complex& c) const {}
// overloaded subtraction operator, to be implemented
Complex Complex::operator -(const Complex& c) const{}
// overloaded multiplication operator, to be implemented
Complex Complex::operator *(const Complex& c) const {}
// overloaded division operator, to be implemented
Complex Complex::operator /(const Complex& c) const {}
// overloaded stream output operator, to be implemented
ostream& operator <<(ostream& os, const Complex& c) {}
template <class T> class myStack{
T *ptr;// storage body
int size;// storage size
int top;// top position
public:
myStack(int);// constructor
~myStack(){free(ptr);}// destructor
bool empty(){return top==-1;}// empty or not
bool full(){return top==size-1;}// full or not
int hold(){return top+1;}// number of items hold
void push(T v){ptr[++top]=v;}// put an item on top
T pop(){return ptr[top--];}// take an item from top
void display(int);// display items
};
// constructor that creates an empty stack, to be implemented
template <class T> myStack<T>::myStack(int s){}
// display function, k items per line, to be implemented
template <class T> void myStack<T>::display(int k){}
// Operator Overloading and Stack Template Program
int main(int argc, char **argv){
// get n, m, and k from command line and create a complex number stack s(n)
// generate n number of random complex numbers and push them onto the stack,
// meantime display these complex numbers, k items per line
// display all complex numbers in the stack, k elements per line
// create two random complex numbers c1 and c2, display c1, c2
// display the results of the addition c1+c2, the subtraction c1-c2, the multiplication c1*c2, and the division c1/c2.
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
- Using the Python language answer the following questions below. Please tell me what program you use if it is IDLE or Atom or a python website please provide the website you use.arrow_forwardPlease write in c++arrow_forwardyour goal is to modify your assignment 6 program to allow the user to pick up a random item and display a sorted list of the contents of the knap sack. note: if you use the built in c++, the most you can make on this assignment is 4 out of 10. you are expected to right your own sort based on one of the algorithms covered in class. your program should have the following: • the name of the program should be assignment 6. • 3 comment lines (description of the program, author, and date). • modify your assignment 5 program to do the following: o display a menu (use a switch statement to implement the menu) of actions ▪ attack: • for now, just display that the user chose to attack ▪ pick up item: • randomly add one of 6 items to an array named knapsack o you get to choose the item names • display which item the user picked up ▪ add an option to the main switch statement: display knap sack contents • the contents of the knap sack must be sorted The knapsack items are bananas, lays,…arrow_forward
- In c++ and without the use of vectors, please. Thanks very much! A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3…arrow_forwardWrite in c++ pleasearrow_forwardCould you show me a different way to write this code in python? I’m trying to make the code simple and easy to understandarrow_forward
- Using c++ Contact list: Binary Search A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Frank 867-5309 Joe…arrow_forwardI need to solve this in C++ code When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by subtracting the smallest value from all the values. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 30 50 10 70 65 the output is: 20 40 0 60 55 For coding simplicity, follow every output value by a space, even the last one. Your program must define and use the following function:int GetMinimumInt(vector<int> listInts) Note: This is a lab from a previous chapter that now requires the use of a function.arrow_forwardC++ Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates a threshold. Output all integers less than or equal to that last threshold value. Ex: If the input is: 5 50 60 140 200 75 100 the program will output: 50,60,75, The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75. The 100 indicates that the program should output all integers less than or equal to 100, so the program outputs 50, 60, and 75. For coding simplicity, follow every output value by a comma, including the last one. You can also safely assume that the number of input integers is always less or equal 10. Such functionality is common on sites like Amazon, where a…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education