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 ​./project1 n m k   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 1. Get the values n, m, and k from the command line. 2. Declare a complex number stack of size n, generate n random complex numbers and push them into the stack. Meantime display all these numbers, k numbers per line. 3. Display all elements of the stack, k elements per line.   4. Create two random complex numbers c1 and c2, display c1,  c2 and the results of the addition c1+c2, the subtraction c1-c2, the multiplication c1*c2, and the division c1/c2.   // project1.cpp   #include #include #include 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 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 myStack::myStack(int s){}​   // display function, k items per line, to be implemented template void myStack::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; }

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter2: Formatting Workbook Text And Data
Section: Chapter Questions
Problem 1.13CP
icon
Related questions
Question

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

1. Get the values n, m, and k from the command line.
2. Declare a complex number stack of size n, generate n random complex numbers and push them into the stack. Meantime display all these numbers, k numbers per line.
3. Display all elements of the stack, k elements per line.  
4. Create two random complex numbers c1 and c2, display c1,  c2 and the results of the addition c1+c2, the subtraction c1-c2, the multiplication c1*c2, and the division c1/c2.

 

// 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;

}

INSERT
DESIGN
PAGE LAYOUT
REFERENCES
MAILINGS
REVIEW
VIEW
FILE
HOME
AaBbCcI AaBbCcI AaBbC AaBbC AaBbC
Heading 1 Heading 2
O Cut
A A
而 T
Times New Ro
11
Aa -
自Copy
al
BIUabs X, xA
A.
T Normal
1 No Spac.
Title
Paste
Format Painter
Font
Paragraph
Clipboard
CSC 212 Projectl.
(100 Points)
the
Read the following program projectl.cpp carefully. Complete the missing code as indicated by
comments. Then compile, debug and test your program using the command lines below before your
submission:
st -o projectl project1.cpp <enter>
Iprojectl 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.
15
In the main function, you need to
1. Get the values n, m, and k from the command line.
2. Declare a complex number stack of size n, generate n random complex numbers and push them
into the stack, Meantime display all these numbers, k numbers per line.
3. Display all elements of the stack, k elements per line.
4. Create two random complex mumbers cl and c2, display cl, c2 and the results of the addition
cl+c2, the subtraction cl-c2, the multiplication c1*c2, and the division c1/c2.
/ Student Name
// Student ID
l projectl.cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
/ complex number class
class Complex {
float re,
float im;
I/ real part
W imagination part
public:
Complex(float =0.0, float i-0.0)frs=r, im-i;}
Complex(const Complex& c){re-c.re; im-c.in;}
void operator(const Complex& c){re c.re; im=c.im;}
Complex operator -Oconst{retum Complex(-re, -im);}
Complex operator Hconst Complex&) const;
Complex operator (const Complex&) const;
Complex operator *(const Complex&) const;
Complex operator (const Complex&) const;
friend ostream& operator <ostream&, const Complex&); output operator
// constructor
/l copy constILuctor
/l assignment
W unary negation
/addition operator
/ subtraction operator
/ multiplication operator
// division operator
/ overloaded addition operator, to be implemented
Complex Complex::operator (const Complex& c) const {}
/ overloaded subtraction onerator, to be implemented
PAGE 2 OF 2
547 WORDS
0哥|
N
WE
Type here to search
Transcribed Image Text:INSERT DESIGN PAGE LAYOUT REFERENCES MAILINGS REVIEW VIEW FILE HOME AaBbCcI AaBbCcI AaBbC AaBbC AaBbC Heading 1 Heading 2 O Cut A A 而 T Times New Ro 11 Aa - 自Copy al BIUabs X, xA A. T Normal 1 No Spac. Title Paste Format Painter Font Paragraph Clipboard CSC 212 Projectl. (100 Points) the Read the following program projectl.cpp carefully. Complete the missing code as indicated by comments. Then compile, debug and test your program using the command lines below before your submission: st -o projectl project1.cpp <enter> Iprojectl 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. 15 In the main function, you need to 1. Get the values n, m, and k from the command line. 2. Declare a complex number stack of size n, generate n random complex numbers and push them into the stack, Meantime display all these numbers, k numbers per line. 3. Display all elements of the stack, k elements per line. 4. Create two random complex mumbers cl and c2, display cl, c2 and the results of the addition cl+c2, the subtraction cl-c2, the multiplication c1*c2, and the division c1/c2. / Student Name // Student ID l projectl.cpp #include <iostream> #include <cstdlib> #include <ctime> using namespace std; / complex number class class Complex { float re, float im; I/ real part W imagination part public: Complex(float =0.0, float i-0.0)frs=r, im-i;} Complex(const Complex& c){re-c.re; im-c.in;} void operator(const Complex& c){re c.re; im=c.im;} Complex operator -Oconst{retum Complex(-re, -im);} Complex operator Hconst Complex&) const; Complex operator (const Complex&) const; Complex operator *(const Complex&) const; Complex operator (const Complex&) const; friend ostream& operator <ostream&, const Complex&); output operator // constructor /l copy constILuctor /l assignment W unary negation /addition operator / subtraction operator / multiplication operator // division operator / overloaded addition operator, to be implemented Complex Complex::operator (const Complex& c) const {} / overloaded subtraction onerator, to be implemented PAGE 2 OF 2 547 WORDS 0哥| N WE Type here to search
1[Compatibility Mode] -Word
Tammy Humphrey
路Find
BbCi AaBbC AaBbCcD AaBbCcD AaBbCcD AaBbCcD AABBCCD AaBbCcl AaBbCcl AABBČCD AABBCCD AaBbCcD
ac Replace
ding 2
Title
Subtitle
Subtle Em... Emphasis
Intense E...
Strong
Quote
Intense Q... Subtle Ref... Intense Re...
Book Title
A Select -
Styles
Editing
Complex Complex::operator -(const Complex& c) const{}
// overloaded multiplication operator, to be implemented
Complex Complex:operator *(const Complex& c) const {}
Il overloaded division operator, to ba 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
// storage size
/l top position
int size,
nt top:
public:
myStack(int);
myStack{free(ptr);}
bool emptyQ{return top=1:}
bool full0{retum top size-1;}
int holdQfretun top+1;}
void push(T v){ptr[++top]=v;}
T pop0{return ptu[top--1:}
void display(int);
/ constructor
// destructor
// empty or not
// full or not
// number of items hold
// put an item on top
// take an item from top
// display items
/l 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)k
/l 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
/l display all complex numbers in the stack, k elements per line
// create two random complex numbers cl 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;
}
100%
9:13 PM
2/27/2021
W
令
ト| Iト
Transcribed Image Text:1[Compatibility Mode] -Word Tammy Humphrey 路Find BbCi AaBbC AaBbCcD AaBbCcD AaBbCcD AaBbCcD AABBCCD AaBbCcl AaBbCcl AABBČCD AABBCCD AaBbCcD ac Replace ding 2 Title Subtitle Subtle Em... Emphasis Intense E... Strong Quote Intense Q... Subtle Ref... Intense Re... Book Title A Select - Styles Editing Complex Complex::operator -(const Complex& c) const{} // overloaded multiplication operator, to be implemented Complex Complex:operator *(const Complex& c) const {} Il overloaded division operator, to ba 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 // storage size /l top position int size, nt top: public: myStack(int); myStack{free(ptr);} bool emptyQ{return top=1:} bool full0{retum top size-1;} int holdQfretun top+1;} void push(T v){ptr[++top]=v;} T pop0{return ptu[top--1:} void display(int); / constructor // destructor // empty or not // full or not // number of items hold // put an item on top // take an item from top // display items /l 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)k /l 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 /l display all complex numbers in the stack, k elements per line // create two random complex numbers cl 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; } 100% 9:13 PM 2/27/2021 W 令 ト| Iト
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage