Starting Out with C++: From Control Structures through Objects, Brief Version (8th Edition)
8th Edition
ISBN: 9780134037325
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 9.5, Problem 9.4CP
What is the output of the following code?
int x = 50, y = 60, z = 70;
int *ptr = nullptr;
cout ≪ x ≪ " " ≪ y ≪ " " ≪ z ≪ endl;
ptr = &x;
*ptr *= 10;
ptr = &y;
*ptr *= 5;
ptr = &z;
*ptr *= 2;
cout ≪ x ≪ " "≪ y ≪ " " ≪ z ≪ endl;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
First, write code that uses cin to read in a value for numTomatoes from input.
Then, write code that uses cout to output "She sold me ", the variable numTomatoes, and " tomatoes." End with a newline.
Ex: If the input is 8, then the output is:
She sold me 8 tomatoes.
Ex: If the input is 9, then the output is:
She sold me 9 tomatoes
#include <iostream>using namespace std;
int main() { int numTomatoes;
/* Your code goes here */
return 0;}
Please use the below code to write code for median and standard deviation. I have already written for Average, Min, and Max value. Thanks!
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
int nums;
int* vals;
double avg;
int min, max;
void* myAvg(void* param)
{
avg = 0.0;
for(inti = 0; i < nums; ++i) {
avg += vals[i];
}
avg /= nums;
pthread_exit(0);
}
void* myMin(void* param)
{
min = vals[0];
for(inti = 1; i < nums; ++i) {
if(min > vals[i])
min = vals[i];
}
pthread_exit(0);
}
void* myMax(void* param)
{
max = vals[0];
for(inti = 1; i < nums; ++i) {
if(max < vals[i])
max = vals[i];
}
pthread_exit(0);
}
int main(int argc, char** argv) {
int i;
nums = (argc - 1);
if(nums <= 0) {
printf("you have to give atleat one value!\n");
return1;
}
vals =…
First, write code that uses cin to read in a value for numLimes from input.
Then, write code that uses cout to output "I bought ", the variable numLimes, and " limes." End with a newline.
Ex: If the input is 6, then the output is:
I bought 6 limes.
Ex: If the input is 8, then the output is:
I bought 8 limes.
#include <iostream>using namespace std;
int main() { int numLimes;
/* Your code goes here */
return 0;}
Chapter 9 Solutions
Starting Out with C++: From Control Structures through Objects, Brief Version (8th Edition)
Ch. 9.5 - Prob. 9.1CPCh. 9.5 - Write the definition statement for a variable...Ch. 9.5 - List three uses of the symbol in C++.Ch. 9.5 - What is the output of the following code? int x =...Ch. 9.5 - Rewrite the following loop so it uses pointer...Ch. 9.5 - Prob. 9.6CPCh. 9.5 - Prob. 9.7CPCh. 9.5 - Is each of the following definitions valid or...Ch. 9.9 - Prob. 9.9CPCh. 9.9 - Give an example of the proper way to call the...
Ch. 9.9 - Complete the following program skeleton. When...Ch. 9.9 - Look at the following array definition: const int...Ch. 9.9 - Assume ip is a pointer to an int. Write a...Ch. 9.9 - Prob. 9.14CPCh. 9.9 - Prob. 9.15CPCh. 9.9 - Prob. 9.16CPCh. 9.9 - Prob. 9.17CPCh. 9 - What does the indirection operator do?Ch. 9 - Look at the following code. int x = 7; int iptr =...Ch. 9 - So far you have learned three different uses for...Ch. 9 - Prob. 4RQECh. 9 - Prob. 5RQECh. 9 - Prob. 6RQECh. 9 - What is the purpose of the new operator?Ch. 9 - What happens when a program uses the new operator...Ch. 9 - Prob. 9RQECh. 9 - Prob. 10RQECh. 9 - Prob. 11RQECh. 9 - Prob. 12RQECh. 9 - Each byte in memory is assigned a unique...Ch. 9 - The _________ operator can be used to determine a...Ch. 9 - Prob. 15RQECh. 9 - The ________ operator can be used to work with the...Ch. 9 - Array names can be used as ________, and vice...Ch. 9 - Prob. 18RQECh. 9 - The ________ operator is used to dynamically...Ch. 9 - Under older compilers, if the new operator cannot...Ch. 9 - Prob. 21RQECh. 9 - When a program is finished with a chunk of...Ch. 9 - You should only use pointers with delete that were...Ch. 9 - Prob. 24RQECh. 9 - Look at the following array definition: int...Ch. 9 - Prob. 26RQECh. 9 - Assume tempNumbers is a pointer that points to a...Ch. 9 - Look at the following function definition: void...Ch. 9 - Prob. 29RQECh. 9 - Prob. 30RQECh. 9 - Prob. 31RQECh. 9 - T F The operator is used to get the address of a...Ch. 9 - T F Pointer variables are designed to hold...Ch. 9 - T F The symbol is called the indirection...Ch. 9 - T F The operator dereferences a pointer.Ch. 9 - T F When the indirection operator is used with a...Ch. 9 - T F Array names cannot be dereferenced with the...Ch. 9 - Prob. 38RQECh. 9 - T F The address operator is not needed to assign...Ch. 9 - T F You can change the address that an array name...Ch. 9 - T F Any mathematical operation, including...Ch. 9 - T F Pointers may be compared using the relational...Ch. 9 - T F When used as function parameters, reference...Ch. 9 - T F The new operator dynamically allocates memory.Ch. 9 - T F A pointer variable that has not been...Ch. 9 - Prob. 46RQECh. 9 - T F In using a pointer with the delete operator,...Ch. 9 - Prob. 48RQECh. 9 - Prob. 49RQECh. 9 - int x, ptr = nullptr; ptr = x;Ch. 9 - Prob. 51RQECh. 9 - Prob. 52RQECh. 9 - Prob. 53RQECh. 9 - float level; int fptr = level;Ch. 9 - Prob. 55RQECh. 9 - Prob. 56RQECh. 9 - Prob. 57RQECh. 9 - Prob. 58RQECh. 9 - int pint = nullptr; pint = new int[100]; //...Ch. 9 - Prob. 60RQECh. 9 - Prob. 61RQECh. 9 - Prob. 62RQECh. 9 - Array Allocator Write a function that dynamically...Ch. 9 - Test Scores #1 Write a program that dynamically...Ch. 9 - Drop Lowest Score Modify Problem 2 above so the...Ch. 9 - Test Scores #2 Modify the program of Programming...Ch. 9 - Prob. 5PCCh. 9 - Case Study Modification #1 Modify Program 9-19...Ch. 9 - Case Study Modification #2 Modify Program 9-19...Ch. 9 - Mode Function In statistics, the mode of a set of...Ch. 9 - Median Function In statistics, when a set of...Ch. 9 - Reverse Array Write a function that accepts an int...Ch. 9 - Array Expander Write a function that accepts an...Ch. 9 - Element Shifter Write a function that accepts an...Ch. 9 - Movie Statistics Write a program that can be used...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
In Section 3.6.8, we saw that a common way to implement switch statements is to create a set of code blocks and...
Computer Systems: A Programmer's Perspective (3rd Edition)
Modify the Java program described in Practice Program 1 so that it adds three numbers instead of two. Compile t...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Give the name of the algorithm that results from each of the following special cases: a. Local beam search with...
Artificial Intelligence: A Modern Approach
Employee and ProductionWorker Classes Create an Employee class that has properties for the following data: Empl...
Starting out with Visual C# (4th Edition)
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction To Programming Using Visual Basic (11th Edition)
True or false: A class object can be passed to a function but cannot be returned by a function.
Starting Out with C++: Early Objects (9th Edition)
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
- please code in java.. dont use very advanced coding Double variable numFeet is read from input. Type cast numFeet to an integer.Ex. If the input is 52.5, then the output is:52arrow_forwardExamine the following code segment. What will be printed? If there are any errors indicate the nature of the error. int a[9] = { 1, 12, 3, 14, 25, 16, 7, 8, 9 }; int *ptr ; ptr = & a[ 2 ] ; for( i = 1; i <= 5; i = i + 2) cout << a[i] << *( ptr + i ); cout << ” ” << a[0] << ” ” << *ptr << ” ” << *ptr - 1 << ” ” << *(ptr - 2));arrow_forwardExplain the steps in finding the output of the following code: #include <iostream>using namespace std; int main() { int arr[5] = {7, 2, 3, 6, 5}; int sum = 0; for (int i = 0; i < 5; ++i) { sum += arr[i]; } cout << " sum : " << sum << endl; return 0;}arrow_forward
- B) What is the value of speed when the following code snippet runs successfully? const int MIN_SPEED = 45; const int MAX_SPEED = 65; int speed = 55; if (!(speed < MAX_SPEED)) { speed = speed - 10; } if (!(speed > MIN_SPEED)) { speed = speed + 10; } C) Assume: int a = 3, b = 2; double c = 5.0; And evaluate the expression and show each step to indicate the evaluation sequence. (c + a / b) / 8 * 2arrow_forwardint a = 4, b;b = a-- + 2;What is the value of b in the above code? a. 7 b. 6 c. Error d. 5arrow_forwardint fun(int k){ return ( ); void main(){ int n; cin >> n; n = n * fun(n); <-- 1 Fill in the appropriate statement and expression in fun, so that when it is called in main, and after the execution of the statement marked 1, the value of n would always be n3.arrow_forward
- C++: Describe how the following call by reference works. Make a comment for each line. void pxc(int& c, int& d) { int k = c; c = d; d = k; } int main() { int a = 15, b = 100; pxc(a, b); }arrow_forwardWhat is the output of the code below? def mystery_func(input, num, t = 0, x = 10, y = 10)[this function multiples all arguments together (except t) and raises the result to the power of t and returns it]print(mystery_func(num = 9, input = 3, t = 1, y = 1))arrow_forwardWhat will be the output of the following C++ code? #include <iostream>using namespace std;enum cat {temp = 7};int main(){int age = 14;age /= temp;cout << "If you were cat, you would be " << age << endl;return 0;}a) If you were cat, you would be 5b) If you were cat, you would be 2c) If you were cat, you would be 7d) If you were cat, you would be 9arrow_forward
- Question 1 is already done need help with the others though This is the C code I have so far #include <stdio.h> #include <stdlib.h> struct employees { char name[20]; int ssn[9]; int yearBorn, salary; }; struct employees **emps = new employees()[10]; //Added new statement ---- bartleby // function to read the employee data from the user void readEmployee(struct employees *emp) { printf("Enter name: "); gets(emp->name); printf("Enter ssn: "); for(int i =0; i <9; i++) scanf("%d", &emp->ssn[i]); printf("Enter birth year: "); scanf("%d", &emp->yearBorn); printf("Enter salary: "); scanf("%d", &emp->salary); } // function to create a pointer of employee type struct employees *createEmployee() { // creating the pointer struct employees *emp = malloc(sizeof(struct employees)); // function to read the data readEmployee(emp); // returning the data return emp; } // function to…arrow_forwardWhat will be the output of code given below. #include <iostream>using namespace std;int main(){int i=10, j=7;cout<<i%j; return 0;}arrow_forwardInteger variable numYards is read from input. Type cast numYards to a double. Ex: If the input is 20, then the output is: 20.00 --Having troublw with this code its supposed to be in C++. #include <iostream>#include <iomanip>using namespace std; int main() {int numYards; cin >> numYards; cout << fixed << setprecision(2) << /* Your code goes here */ << endl; return 0;}arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended 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 Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY