Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 16, Problem 37RQE
template <class T>
T square(T number)
{
return T * T;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
#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&…
#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&…
in c++: Implement the Array class that is defined below and test it in the main program. The main program must test all the member functions including the overloaded operators that are defined in the class:
#ifndef array_h
#define array_h
#include <iostream>
using namespace std;
class Array { // Class declaration
friend const Array operator+(const Array & a1, const Array &a2);
friend bool operator==(const Array & a, const Array &b);//Equality test
public:
Array(int = 10); //Initialize the array with 0 values, default size =10
Array(const Array & a); // copy constructor
~Array();//Destructor
int getSize();// return the size of the array.
const Array & operator=(const Array & a);//assignement operator
Array operator+(int x);//+ operator
bool operator!=(const Array & a) const;//Not equal test
void read();
void print();
Array operator-();//Negate (unary operation)…
Chapter 16 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 16.1 - Prob. 16.1CPCh. 16.1 - Prob. 16.2CPCh. 16.1 - Prob. 16.3CPCh. 16.1 - Prob. 16.4CPCh. 16.1 - Prob. 16.5CPCh. 16.3 - Prob. 16.6CPCh. 16.3 - The following function accepts an i nt argument...Ch. 16.3 - Prob. 16.8CPCh. 16.3 - Prob. 16.9CPCh. 16.4 - Prob. 16.10CP
Ch. 16.4 - Prob. 16.11CPCh. 16 - Prob. 1RQECh. 16 - Prob. 2RQECh. 16 - Prob. 3RQECh. 16 - Prob. 4RQECh. 16 - What is unwinding the stack?Ch. 16 - What happens if an exception is thrown by a classs...Ch. 16 - How do you prevent a program from halting when the...Ch. 16 - Why is it more convenient to write a function...Ch. 16 - Why must you be careful when writing a function...Ch. 16 - The line containing a throw statement is known as...Ch. 16 - Prob. 11RQECh. 16 - Prob. 12RQECh. 16 - Prob. 13RQECh. 16 - The beginning of a template is marked by a(n)...Ch. 16 - Prob. 15RQECh. 16 - Prob. 16RQECh. 16 - Write a function that searches a numeric array for...Ch. 16 - Write a function that dynamically allocates a...Ch. 16 - Make the function you wrote in Question 17 a...Ch. 16 - Write a template for a function that displays the...Ch. 16 - Prob. 21RQECh. 16 - Prob. 22RQECh. 16 - Prob. 23RQECh. 16 - Prob. 24RQECh. 16 - T F All type parameters defined in a function...Ch. 16 - Prob. 26RQECh. 16 - T F A class object passed to a function template...Ch. 16 - Prob. 28RQECh. 16 - Prob. 29RQECh. 16 - Prob. 30RQECh. 16 - Prob. 31RQECh. 16 - T F A class template may not be derived from...Ch. 16 - T F A class template may not be used as a base...Ch. 16 - Prob. 34RQECh. 16 - Prob. 35RQECh. 16 - try { quotient = divide(num1, num2); } cout The...Ch. 16 - template class T T square(T number) { return T T;...Ch. 16 - template class T int square(int number) { return...Ch. 16 - Prob. 39RQECh. 16 - Assume the following definition appears in a...Ch. 16 - Assume the following statement appears in a...Ch. 16 - Prob. 1PCCh. 16 - Prob. 2PCCh. 16 - Prob. 3PCCh. 16 - Prob. 4PCCh. 16 - Prob. 5PCCh. 16 - IntArray Class Exception Chapter 14 presented an...Ch. 16 - TestScores Class Write a class named TestScores....Ch. 16 - Prob. 8PCCh. 16 - Prob. 9PCCh. 16 - SortableVector Class Template Write a class...Ch. 16 - Inheritance Modification Assuming you have...Ch. 16 - Prob. 12PCCh. 16 - Prob. 13PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
In the text, JUMP instructions were expressed by identifying the destination explicitly by stating the name (or...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Explain how each of the following types of integrity constraints is enforced in the SQL CREATE TABLE commands: ...
Modern Database Management (12th Edition)
Why is it critical that accumulator variables are properly initialized?
Starting Out with Programming Logic and Design (4th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Show how to use the constructor of the fstream class to open a file for input without having to call the open f...
Starting Out with C++: Early Objects
True or False: A variable may be defined in the initialization expression of the for loop.
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Knowledge Booster
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
- Q1/ find code optimization of this code then find type to this code. for (i=1;iarrow_forwardC++ Code /////// #include <iostream> class BTNode {public:int item;BTNode *left;BTNode *right;BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){}}; BTNode *root = nullptr; void insert(int i) {//implement code here} int main(){insert (5);insert (10);insert (1);if (root){std::cout << "root = " << root->item << std::endl;if (root->left)std::cout << "root->left = " << root->left->item << std::endl;if (root->right)std::cout << "root->right = " << root->right->item << std::endl;}return 0;}arrow_forward} BMI(struct Person* person) { person->BMI = person->weight / (person->height person->height); return person->BMI; } //Q10: Why is the return type char*? char* determineWeightCategory(struct Person* person) {//assumes BMI is known const double UNDERWEIGHT = 18.5; const double NORMALWEIGHT = 24.9; const double OVERWEIGHT = 29.9; } else { //Q11: If the value in person->BMI is equal to 18.5 and person is athletic, what will be //stored in p- //Q12: The first if statement validates against certain conditions. //What are the conditions it is validating against? //HINT: Think about what causes BMI to be less than 0. if (person->BMI weightCategory, "ERROR"); } else if (person->BMI weightCategory, "Underweight"); } else if (person->BMI weightCategory, "Normalweight"); } else if (person->BMI weightCategory, "Overweight"); strcpy(person->weightCategory, "Obese"); return person->weightCategory; //Q13: Why do we return person->weightCategory? } //Q14: Why is provider passed by value?arrow_forward#include using namespace std; class Student{ public: Student() { cout<<"Hello"<arrow_forward#include #include using namespace std; class Staff{ public: int code; string name; public: Staff(){} Staff(int code, string name){ this->code = code; this->name = name; } Staff(const Staff &s){ this->code=s.code; this->name = s.name; } int getCode(){ return code; } void setCode(int c){ code = c; } string getName(){ return name; } void setName(string n){ name = n; }; class Faculty: public Staff{ public: int department; string subjectTaken; string researchArea; Faculty(int code,string name,int department, string subjectTaken, string researchArea):Staff(code,name) { this->department = department; this->subjectTaken = subjectTaken; this->researchArea = researchArea; } Faculty() { } Faculty(const Faculty &f){ code = f.code; name = f.name; department = f.department; subjectTaken = f.subjectTaken; researchArea = f.researchArea; } int getDepartment() { return department; } void setDepartment(int department) {…arrow_forwardQ2: Complete the main programs and writing its functions, classes and find the Area for each shape: 1- Main() { Circle C [3]={12,51,7}; C.setdate('3'); // Circle class has private members: radius,arrow_forwardC:/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_forwardfunction carLambda = [rank, &price] ()->int { cout name); model Car:: carModel; auto testLambdaPtr = testLambda (); cout << testLambdaPtr () << endl; return 0; I a. In which memory area is this element stored? Please state your choice and explain why? b. The lifetime, beginning & end, of this element? Why?arrow_forwardLanguge : c++ Question : Make a program to overload the * operator for multiplying a Distance class object with a integer. The Distance class should have meters and kilometres as data members. Add all appropriate member functions for the program to work properly. In addition, make the main function to test your class as follows: int main() { Distance dist(2, 700); dist= dist * 2; dist.display(); return 0;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#include<bits/stdc++.h>using namespace std; // Class representing music dataclass Song {public:string musicName, musicDescription;};// Function to take input for music descriptionSong addDescription(){Song s1;cout<<"Enter the Music name : ";cin>>s1.musicName;cout<<"Enter the Music description : ";cin>>s1.musicDescription;return s1;} // Function to write music object details into a txt filevoid storeInfoToDatabase(Song s){ofstream fileObject;// Opening the file in append modefileObject.open("Database.txt", ios::app);fileObject << s.musicName;fileObject << " ";fileObject << s.musicDescription;fileObject << "\n";} // Driver Functionint main(){Song s = addDescription();storeInfoToDatabase(s);cout<<"Data written into file succesfully...";return 0;}arrow_forwardY3arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY