Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10, Problem 32RQE
Program Plan Intro
Shared pointers:
- A “shared_ptr” is a smart pointer which maintains shared ownership of an object using pointer.
- Shared pointers are used in managing the ownership of the dynamically allocated object.
- Shared pointers are used by more than one owner available for the objects that are allocated dynamically.
Example:
The following code illustrates the use and creation of shared pointer:
//creating a shared pointer of integer data type
shared_ptr<int> sDPtr1 (new int);
//creating an array of shared pointer
shared_ptr<int[]> sDPtr2 (new int[5]);
Explanation:
In the above code snippet, a smart pointer of integer data type is assigned directly.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++ Programming Problem:
Newton is a brilliant mathematician and solving triangles problems fascinates him. Today he is given
a sequence of positive integers V1, V2, ., VN. You must choose three elements Vx, Vy, Vz (x, y, z is
vertices) such that the triangle formed have these properties: |XY|= Vz, |XZ|=Vy, |YZ|=Vx and the
angle |ZYXZ|= 0 satisfies cose2P/Q, where 0 should be maximum possible. Find any such triangle or
determine that it does not exist. Develop a C++ code which prints the value of x, y, z in a single line
and print "Invalid" if not possible.
Test Case:
412
9765
Result:
324
#include<iostream>using namespace std;void main(){double pi = 0, denominator = 1;int counter = 999999;for (int x = 0; x < counter; x++){if (x % 2 != 0){pi = pi - (1 / denominator);}else{pi = pi + (1 / denominator);}denominator = denominator + 2;}pi = pi * 4;cout << " So the computed value of a PI is = " << pi << endl;cout << " ";//return 0;system("pause");}
Note:
This a program called ComputePI to compute the value of π
Tutor just have to Modify This program to use nested-if (if ... else if ... else if ... else) instead.
Explain by applying a double line comment
c++ coding language
I need help with part B and C please. If you are unable to do both, then
PLEASE prioritize part C. I am really stuck and really can use the help.
This is the code for c that was provided in order to guide me:
const int N =31; // N parking spaces
bool parking[N]; // the garage
void EmptyTheLot(bool parking[], int N) {
for(int i=0; i<N; i++) p[i]=false; // empty space
}
// returns -1 if no space found,
//otherwise it returns 0<=i<N for a valid space.
int FindSpace(int PlateNumber, bool parking[], int N)
{
// ?????
}
main() {
EmptyTheLot(parking, N); // start with an empty parking garage. // get plate numbers and fill lot.
}
Chapter 10 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 10.5 - Prob. 10.1CPCh. 10.5 - Write a statement defining a variable dPtr. The...Ch. 10.5 - List three uses of the symbol in C++.Ch. 10.5 - What is the output of the following program?...Ch. 10.5 - Rewrite the following loop so it uses pointer...Ch. 10.5 - Prob. 10.6CPCh. 10.5 - Assume pint is a pointer variable. For each of the...Ch. 10.5 - For each of the following variable definitions,...Ch. 10.10 - Assuming array is an array of ints, which of the...Ch. 10.10 - Give an example of the proper way to call the...
Ch. 10.10 - Complete the following program skeleton. When...Ch. 10.10 - Look at the following array definition: const int...Ch. 10.10 - Assume ip is a pointer to an int. Write a...Ch. 10.10 - Assume ip is a pointer to an int. Write a...Ch. 10.10 - Prob. 10.15CPCh. 10.10 - Prob. 10.16CPCh. 10.10 - Prob. 10.17CPCh. 10.12 - Prob. 10.18CPCh. 10.12 - Assume the following structure declaration exists...Ch. 10.12 - Prob. 10.20CPCh. 10 - Each byte in memory is assigned a unique _____Ch. 10 - The _____ operator can be used to determine a...Ch. 10 - Prob. 3RQECh. 10 - The _____ operator can be used to work with the...Ch. 10 - Prob. 5RQECh. 10 - Creating variables while a program is running is...Ch. 10 - Prob. 7RQECh. 10 - If the new operator cannot allocate the amount of...Ch. 10 - Prob. 9RQECh. 10 - When a program is finished with a chunk of...Ch. 10 - You should only use the delete operator to...Ch. 10 - What does the indirection operator do?Ch. 10 - Look at the following code. int X = 7; int ptr =...Ch. 10 - Name two different uses for the C++ operator.Ch. 10 - Prob. 15RQECh. 10 - Prob. 16RQECh. 10 - Prob. 17RQECh. 10 - What is the purpose of the new operator?Ch. 10 - What happens when a program uses the new operator...Ch. 10 - Prob. 20RQECh. 10 - Prob. 21RQECh. 10 - Prob. 22RQECh. 10 - Prob. 23RQECh. 10 - Prob. 24RQECh. 10 - Prob. 25RQECh. 10 - Prob. 26RQECh. 10 - What happens when a unique_ptr that is managing an...Ch. 10 - What does the get ( ) method of the unique_ptr...Ch. 10 - Prob. 29RQECh. 10 - Prob. 30RQECh. 10 - Prob. 31RQECh. 10 - Prob. 32RQECh. 10 - Consider the function void change(int p) { P = 20;...Ch. 10 - Prob. 34RQECh. 10 - Write a function whose prototype is void...Ch. 10 - Write a function void switchEnds(int array, int...Ch. 10 - Given the variable initializations int a[5] = {0,...Ch. 10 - Each of the following declarations and program...Ch. 10 - Prob. 39RQECh. 10 - Test Scores #1 Write a program that dynamically...Ch. 10 - Test Scores #2 Modify the program of Programming...Ch. 10 - Indirect Sorting Through Pointers #1 Consider a...Ch. 10 - Indirect Sorting Through Pointers #2 Write a...Ch. 10 - Pie a la Mode In statistics the mode of a set of...Ch. 10 - Median Function In statistics the median of a set...Ch. 10 - Movie Statistics Write a program that can be used...Ch. 10 - Days in Current Month Write a program that can...Ch. 10 - Age Write a program that asks for the users name...Ch. 10 - Prob. 10PC
Knowledge Booster
Similar questions
- C++ 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_forwardC++ PROGRAMMINGTopic: HashTable - PolyHash Quadratic Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed). You can also explain line by line for an upvote, thanks. EXPLAIN THE CODE BELOW: #include <cstdlib> #include <math.h> #include <cstring> #include <iostream> using namespace std; class HashTable { string* table; int N; int count; // TODO: Polynomial Hash Code using a=7 int hash_code(string key) { int code; int hash = 0; for (int i = 0; i < key.size(); i++) { char ch = key[i]; code += ((ch - 96) * pow(7, key.size() - (i + 1))); } return code; } // TODO: This hash table uses a MAD compression function // where a = 11, b = 461, p = 919 int compress(int code) { return (((11*code)+461) % 919) % N; }…arrow_forwardint func(int a, int b) { return (aarrow_forwardtonquage accepting any no.fa's } prite a P.E for the and b's over, & = {a,b?arrow_forwardIn Python, grades_dict = {'Wally': [87,96,70], 'Eva': [100,87,90], 'Sam': [94,77,90], 'Katie': [100,81,82], 'Bob': [83,65,85]} Write your own describe function that produces the same 8 statistical results, for each one of the columns, that the built-in describe() function does. Note 1: Use the sample standard deviation formula (that is, the denominator is: N-1) Note 2: Your algorithm should work for any number of columns not just for 5 Note 3: You can use the np.percentile() for the 25% and 75% percentile as well as the sort() built-in functionsarrow_forwarddebugarrow_forward#include using namespace std; void some_action_1(int); int main() { cout<arrow_forwardIn the C programming language, if all function prototypes are listed at the top of your code, outside and above all functions, you do not need to worry about the order of the function definitions within the code. True Falsearrow_forwardIn Python, grades_dict = {'Wally': [87,96,70], 'Eva': [100,87,90], 'Sam': [94,77,90], 'Katie': [100,81,82], 'Bob': [83, 65, 85]} write your own describe function that produces thesame 8 statistical results, for each one of the columns, that the built-in describe() function does.Note 1: Use the sample standard deviation formula (that is, the denominator is: N-1)Note 2: Your algorithm should work for any number of columns not just for 5Note 3: You can use the np.percentile() for the 25% and 75% percentile as well as the sort()built-in functionsarrow_forwardLanguage: C++ Use the previously given files: Critter.h, Critter.cpp and testcritter.cpp. Expand Critter.h by two additional properties of your choice, and corresponding setter and getter methods, then adjust Critter.cpp and testcritter.cpp accordingly. Also adapt the print () method such that the new properties are printed on the screen as well. You can assume that the input will be valid.arrow_forwardC++ in visual studio: Implement it completely with copy constructor, overloaded assignment operator and destructor. Then, in main, type an application that creates 2 numbers, sums them, and assigns the result to a new number. for example ; Number 1 (18,32) Number 2 (15.09) - - - - - - - - - - - + Number 3 ( 33,41)arrow_forwardJAVA LANGUAGE CODE Postfix Calculator by CodeChum Admin One good implementation of computing infix expressions is to transform them to postfix and then evaluate via the postfix expression. Infix expressions is the common way of writing arithmetic expressions. The binary operator come between them as shown below: 2 * 5 + 9 - 10 / 20 In postfix expressions, the operands come first before the operator: 2 5 * 9 + 10 20 / - A stack can be used to evaluate postfix expressions. The operands are pushed onto the Stack and when an operator is found two operands are popped and the operation is performed and finally the result is pushed back onto the Stack. The final answer will be the lone element of the Stack. Input The first line contains a positive integer n representing the number of postfix expressions. What follows are n postfix expressions themselves. 5 10 20 + 30 15 2 * + 100 20 30 + / 90 20 10 + + 0 / 9 3 - 10 + 2 * Output A single line containing the result of…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT