Concept explainers
Trending nowThis is a popular solution!
Chapter 13 Solutions
C++ Programming: From Problem Analysis to Program Design
- Assurne class LinkedQueue has been defined using the irplementation in your textbook thet myQueue has been initialized sa it is empty. Type the EXACT output of the following code segment. You may assurne that the code compiles and executes without erors. LinkedQueue myQueue int i - 1: int j-2; int k-3; int n-43B ryQueue.enqueue (n) myQueue.enquese G i- myQueue.peekFront (): myQueue.dequeue ( myQueue.cmqueue kk n-myQueue.peekFront (k myQueue.dequeue ( myQueue.enqueue (n) 2 aranbuarananbAu while CmyQueueisEmpty () i-myQueue.peckFront (k myQueue.dequeue(k cout <arrow_forwardPROGRAMMING LANGUAGE: C++ // vectors: overloading operators example#include <iostream>using namespace std;class counter{private:int count;public:counter():count(0){}counter(int c):count(c) {} int get_count(){return count;} counter operator++ (int){return counter(count++); } counter operator-- (int){return counter(count--);}};int main(){counter c1, c2, c3;c1++;c2--;cout<<'\n'<<c1.get_count();cout<<'\n'<<c2.get_count();cout<<endl;c3 = c1++;cout<<'\n'<<c1.get_count();cout<<'\n'<<c3.get_count();getch();return 0;} Go through the above code and write the output of the given code segment. counter c1(5), c2(10), c3;c3=c1++;c2=--c3;;cout<<”\n”<<c1.get_count();cout<<”\n”<<c2.get_count();cout<<”\n”<<c3.get_count();arrow_forwardC++ Code, Function below is not a member function of Sequence class: void subtractX(Sequence<int>& s, int& x) //! updates s //! clears x //! ensures: s = #s with all corresponding values of s reduced by value in #x { for (int k = 0, z = s.length(); k < z; k++) { // s1.1, s1.2, s1.3, s1.4 int y; s.remove(k, y); // s2 y -= x; // s3 s.add(k, y); // s4 } // end for x.clear(); // s5 } // END subtractX For the function above, a. Draw the code diagrams with labels for statements and branches. b. Provide test cases for statement, branch, and path coverages (properly identifying all the test cases with correct labels and the respective function).arrow_forwardSmart Pointer: Write a smart pointer class. A smart pointer is a data type, usually implemented with templates, that simulates a pointer while also providing automatic garbage collection. It automatically counts the number of references to a SmartPointer<?> object and frees the object of type T when the reference count hits zero.arrow_forwardComputer Science Write in Javascript please and use high order functions liek map or filter or reduce let obj = [ { mode: "hot" }, { temp: "low" }, { mode: "cold } ] I want to create a function that get object by key such as: myFunc("mode"); returns { mode: "hot" } next call of myFunc("mode") returns { mode: "coldarrow_forwardprogramming language :c++ make a program in c++ to store hiring date and date of birth for Managers and Employees. You need to create a Date class for this purpose. Create objects of Date class in Manager and Employee classes to store respective dates. You need to write print function in Manager and Employee classes as well to print all information of Managers and Employees. You need to perform composition to implement this task. Create objects of Manager and Employee classes in main function and call print function for both objects. Print Date class here. Print updated Manager class here. Print updated Employee class here. Print main function here.arrow_forwardNot sure how to fix the getIndex function please help --------------------------- #include <iostream> #include <cassert> using namespace std; class SomeObj{ public: SomeObj(int d ): id(d){} int getId() const; void output(); private: int id; }; int SomeObj::getId() const{ return id; } void SomeObj::output(){ cout<<id<<endl; } template<typename T> class MyArray { public: MyArray(); MyArray(int c); T& operator[](int index); void push_back(T e); int getSize() const; int getCapacity() const; int getIndex(T a); void erase(); private: void grow(); T *data; int capacity; int size; }; template <typename T> MyArray<T>::MyArray(): MyArray(1) { } template <typename T> MyArray<T>::MyArray(int c) { assert(c>0); size = 0; capacity = c; data = new T[capacity]; } template <typename T> T& MyArray<T>::operator[](int index) {…arrow_forwardGiven the code:class DigitalWallet {private; long *id; // wallet id long *accounts; // dynamic array of account numbers int numAccounts; // number of user accounts in the array}1. Write a function definition for a Constructor to initialize all data members.2. Write a function definition for the Copy Constructor.3. Write a function definition for the Destructor.arrow_forwardIn C++ The base class Pet has private data members petName, and petAge. The derived class Dog extends the Pet class and includes a private data member for dogBreed. Complete main() to: create a generic pet and print information using PrintInfo(). create a Dog pet, use PrintInfo() to print information, and add a statement to print the dog's breed using the GetBreed() function. Ex. If the input is: Dobby2Kreacher3German Schnauzer the output is: Pet Information: Name: Dobby Age: 2Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzerarrow_forward#include <iostream> using namespace std;struct Triple{int row, col, value;}; class Matrix; class MatrixNode{friend class Matrix;friend istream& operator>>(istream&, Matrix&);private:MatrixNode *down, *right;bool head;union{MatrixNode *next;Triple triple;};MatrixNode(bool, Triple*);}; MatrixNode::MatrixNode(bool b, Triple *t){head = b;if (b){right = down = this;}else triple = *t;};class Matrix{friend istream& operator>>(istream&, Matrix&);public:~Matrix();MatrixNode*private:MatrixNode *headnode;}; Matrix::~Matrix(){// Return all nodes to the av list, which is a chain linked// via the right field.// av is a static variable pointing to the first of the av list.if (!headnode )return; // no nodes to deleteMatrixNode *x = headnode->right; headnode->right = av;av = headnode; // return headnode while (x != headnode) { // return nodes by rowsMatrixNode *y = x->right;x->right = av;av = y;x = x->next; // next row}headnode = 0;} istream&…arrow_forward#include <iostream> using namespace std;struct Triple{int row, col, value;}; class Matrix; class MatrixNode{friend class Matrix;friend istream& operator>>(istream&, Matrix&);private:MatrixNode *down, *right;bool head;union{MatrixNode *next;Triple triple;};MatrixNode(bool, Triple*);}; MatrixNode::MatrixNode(bool b, Triple *t){head = b;if (b){right = down = this;}else triple = *t;};class Matrix{friend istream& operator>>(istream&, Matrix&);public:~Matrix();MatrixNode*private:MatrixNode *headnode;}; Matrix::~Matrix(){// Return all nodes to the av list, which is a chain linked// via the right field.// av is a static variable pointing to the first of the av list.if (!headnode )return; // no nodes to deleteMatrixNode *x = headnode->right; headnode->right = av;av = headnode; // return headnode while (x != headnode) { // return nodes by rowsMatrixNode *y = x->right;x->right = av;av = y;x = x->next; // next row}headnode = 0;} istream&…arrow_forwardC++ ProgrammingActivity: Deque Linked List Explain the flow of the main code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow. SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS int main(int argc, char** argv) { DLLDeque* deque = new DLLDeque(); int test; cin >> test; //Declarations int tempnum; int num; int sum; int count; bool addfirst = false; bool addlast = false; bool remfirst = false; bool remlast = false; switch (test) { case 0: //Implementation do{ cin >> num; if(num == 0){ break; } //Reset tempnum = num; count = 0; sum = 0; addfirst = false; addlast = false; remfirst = false; remlast =…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning