
EBK STARTING OUT WITH C++
8th Edition
ISBN: 8220100794438
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 3, Problem 21RQE
Program Description Answer
The library functions which result in base-10 logarithm of a number is “log10()”.
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these similar questions
The next problem concerns the following C code:
/copy input string x to buf */
void foo (char *x) {
char buf [8];
strcpy((char *) buf, x);
}
void callfoo() {
}
foo("ZYXWVUTSRQPONMLKJIHGFEDCBA");
Here is the corresponding machine code on a Linux/x86 machine:
0000000000400530 :
400530:
48 83 ec 18
sub
$0x18,%rsp
400534:
48 89 fe
mov
%rdi, %rsi
400537:
48 89 e7
mov
%rsp,%rdi
40053a:
e8 di fe ff ff
callq
400410
40053f:
48 83 c4 18
add
$0x18,%rsp
400543:
c3
retq
400544:
0000000000400544 :
48 83 ec 08
sub
$0x8,%rsp
400548:
bf 00 06 40 00
mov
$0x400600,%edi
40054d:
e8 de ff ff ff
callq 400530
400552:
48 83 c4 08
add
$0x8,%rsp
400556:
c3
This problem tests your understanding of the program stack. Here are some notes to
help you work the problem:
⚫ strcpy(char *dst, char *src) copies the string at address src (including
the terminating '\0' character) to address dst. It does not check the size of
the destination buffer.
• You will need to know the hex values of the following characters:
1234
3. Which line prevents compiler optimization? Circle one: 1234
Suggested solution:
Store strlen(str) in a variable before the if statement.
⚫ Remove the if statement.
Replace index 0 && index < strlen(str)) {
5 }
}
=
str [index] = val;
Character Hex value | Character Hex value Character Hex value
'A'
0x41
'J'
Ox4a
'S'
0x53
'B'
0x42
'K'
0x4b
"T"
0x54
0x43
'L'
Ox4c
'U'
0x55
0x44
'M'
0x4d
'V'
0x56
0x45
'N'
Ox4e
'W'
0x57
0x46
'0'
Ox4f
'X'
0x58
0x47
'P'
0x50
'Y'
0x59
0x48
'Q'
0x51
'Z'
Ox5a
'T'
0x49
'R'
0x52
'\0'
0x00
Now consider what happens on a Linux/x86 machine when callfoo calls foo with
the input string "ZYXWVUTSRQPONMLKJIHGFEDCBA".
A. On the left draw the state of the stack just before the execution of the instruction
at address Ox40053a; make sure to show the frames for callfoo and foo and
the exact return address, in Hex at the bottom of the callfoo frame.
Then, on the right, draw the state of the stack just after the instruction got
executed; make sure to show where the string "ZYXWVUTSRQPONMLKJIHGFEDCBA"
is placed and what part, if any, of the above return address has been overwritten.
B. Immediately after the ret instruction at address 0x400543 executes, what is
the value of the program counter register %rip?…
Chapter 3 Solutions
EBK STARTING OUT WITH C++
Ch. 3.1 - Prob. 3.1CPCh. 3.1 - Prob. 3.2CPCh. 3.1 - Assume value is an integer variable. If the user...Ch. 3.1 - A program has the following variable definitions....Ch. 3.1 - Prob. 3.5CPCh. 3.1 - Complete the following program skeleton so it asks...Ch. 3.2 - Complete the table below by determining the value...Ch. 3.2 - Write C++ expressions for the following algebraic...Ch. 3.2 - Prob. 3.9CPCh. 3.2 - Complete the following program skeleton so it...
Ch. 3.5 - Assume the following variable definitions: int a =...Ch. 3.5 - Complete the following program skeleton so it asks...Ch. 3.5 - Prob. 3.13CPCh. 3.6 - Write a multiple assignment statement that assigns...Ch. 3.6 - Write statements using combined assignment...Ch. 3.6 - Prob. 3.16CPCh. 3.7 - Write cout statements with stream manipulators...Ch. 3.7 - Prob. 3.18CPCh. 3.7 - The following program skeleton asks for an angle...Ch. 3.9 - Prob. 3.20CPCh. 3.9 - Assume the variables angle1 and angle2 hold angles...Ch. 3.9 - To find the cube root (the third root) of a...Ch. 3.9 - The cosecant of the angle a is 1sina Write a...Ch. 3 - Assume the following variables are defined: int...Ch. 3 - Prob. 2RQECh. 3 - Prob. 3RQECh. 3 - Complete the following table by determining the...Ch. 3 - Write C++ expressions for the following algebraic...Ch. 3 - Assume a program has the following variable...Ch. 3 - Assume a program has the following variable...Ch. 3 - Assume qty and salesReps are both integers. Use a...Ch. 3 - Rewrite the following variable definition so that...Ch. 3 - Complete the following table by providing...Ch. 3 - Write a multiple assignment statement that can be...Ch. 3 - Write a cout statement so the variable divSales is...Ch. 3 - Write a cout statement so the variable totalAge is...Ch. 3 - Prob. 14RQECh. 3 - The__________ library function returns the cosine...Ch. 3 - The ___________ library function returns the sine...Ch. 3 - The ________ library function returns the tangent...Ch. 3 - The __________ library function returns the...Ch. 3 - The _________ library functionreturns the...Ch. 3 - The _________ library function returns the natural...Ch. 3 - Prob. 21RQECh. 3 - The _______ library function returns the value of...Ch. 3 - The _________ libraryfunction returns the square...Ch. 3 - The ________ file must beincluded in aprogramthat...Ch. 3 - A retail store grants its customers a maximum...Ch. 3 - Write a pseudocode algorithm for a program that...Ch. 3 - Write a pseudocode algorithm for a program that...Ch. 3 - using namespace std; int main () { double number1,...Ch. 3 - #include iostream using namespace std; int main()...Ch. 3 - #include iostream; using namespace std; int main()...Ch. 3 - #include iostream; using namespace std; main { int...Ch. 3 - #inc1ude iostream; using namespace std; main {...Ch. 3 - #inc1ude iostream; using namespace std; int main()...Ch. 3 - What will each of the following programs display?...Ch. 3 - #include iostream using namespace std; int main()...Ch. 3 - (Assume the user enters George Washington.)...Ch. 3 - (Assume the user enters 36720152. Use a...Ch. 3 - Miles per Gallon Write a program that calculates a...Ch. 3 - Stadium Seating There are three seating categories...Ch. 3 - Test Average Write a program that asks for five...Ch. 3 - Average Rainfall Write a program that calculates...Ch. 3 - Ingredient Adjuster A cookie recipe calls for the...Ch. 3 - Box Office A movie theater only keeps a percentage...Ch. 3 - How Many Widgets? The Yukon Widget Company...Ch. 3 - How Many Calories? A bag of cookies holds 30...Ch. 3 - How Much Insurance? Many financial experts advise...Ch. 3 - Automobile Costs Write a program that asks the...Ch. 3 - Celsius to Fahrenheit Write a program that...Ch. 3 - Currency Write a program that will convert U.S....Ch. 3 - Monthly Sales Tax A retail company must file a...Ch. 3 - Property Tax A county collects property taxes on...Ch. 3 - Senior Citizen Property Tax Madison County...Ch. 3 - Math Tutor Write a program that can be used as a...Ch. 3 - Interest Earned Assuming there are no deposits...Ch. 3 - Monthly Payments The monthly payment on a loan may...Ch. 3 - Pizza Pi Joes Pizza Palace needs a program to...Ch. 3 - Angle Calculator Write a program that asks the...Ch. 3 - Stock Transaction Program Last month Joe purchased...Ch. 3 - Word Game Write a program that plays a word game...
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
- 1 typedef struct node* { 2 struct node* next; 3 char* key; 4 char* val; 5} node_t; 6 7 char* find_node (node_t* node, char* key_to_find) { while(strcmp (node->key, key_to_find ) != 0 ) { node = node->next; 8 9 10 } 11 return node->val; 12 }arrow_forwardMatch each of the assembler routines on the left with the equivalent C function on the right. Write the name of the label (e.g., foo) to the right of the corresponding function. Note: shrq is the logical right shift instruction, and sarq is the arithmetic right shift instruction. foo1: leaq 0(,%rdi, 8), %rax long choice1 (long x) { ret return x - 8 >8; foo3: } movq sarq %rdi, %rax $8, %rax long choice4 (long x) ret { return x*256; } foo4: long choice5 (long x) leaq -8 (%rdi), %rax { ret return x-8; } long choice6 (long x) foo5: { leaq -8 (%rdi), %rax return x+8; shrq $63, %rax } retarrow_forwardGiven the variables and code in the text below, identify where in memory they will live once the code is compiled. 1 char big_array [1L<<24]; /* 16 MB */ 2 GB * :/ 2 char huge_array [1L<<31]; /* 3 4 int global = 0; 5 6 int useless () { return 0; } 7 8 int main() 9 { 10 void *p1, p2, *p3, *p4; int local = 0; malloc (1L << 28); /* 256 MB *, 11 12 p1 13 p2 = malloc (1L << 8); /* 256 B * 14 p3 15 p4 = malloc (1L << 32); malloc (1L << 8); /* 4 GB * */ /* 256 B */ 16 } Note: *pN is the thing at which pN points. 1. big_array 2. huge_array 3. global 4. useless 5. void* p1 6. *p1 7. void* p2 8. *p2 9. void* p3 10. *p3 11. void* p4 12. *p4arrow_forward
- The next problem concerns the following C code: /copy input string x to buf */ void foo (char *x) { char buf [8]; strcpy((char *) buf, x); } void callfoo() { } foo("ZYXWVUTSRQPONMLKJIHGFEDCBA"); Here is the corresponding machine code on a Linux/x86 machine: 0000000000400530 : 400530: 48 83 ec 18 sub $0x18,%rsp 400534: 48 89 fe mov %rdi, %rsi 400537: 48 89 e7 mov %rsp,%rdi 40053a: e8 di fe ff ff callq 400410 40053f: 48 83 c4 18 add $0x18,%rsp 400543: c3 retq 400544: 0000000000400544 : 48 83 ec 08 sub $0x8,%rsp 400548: bf 00 06 40 00 mov $0x400600,%edi 40054d: e8 de ff ff ff callq 400530 400552: 48 83 c4 08 add $0x8,%rsp 400556: c3 This problem tests your understanding of the program stack. Here are some notes to help you work the problem: ⚫ strcpy(char *dst, char *src) copies the string at address src (including the terminating '\0' character) to address dst. It does not check the size of the destination buffer. • You will need to know the hex values of the following characters:arrow_forwardConsider the following assembly code for a C for loop: movl $0, %eax jmp .L2 .L3: addq $1, %rdi addq %rsi, %rax subq $1, %rsi .L2: cmpq %rsi, %rdi jl .L3 addq ret %rdi, %rax Based on the assembly code above, fill in the blanks below in its corresponding C source code. Recall that registers %rdi and %rsi contain the first and second, respectively, argument of a function. (Note: you may only use the symbolic variables x, y, and result in your expressions below do not use register names.) long loop (long x, long y) { long result; } for ( } return result; __; y--) {arrow_forwardIn each of the following C code snippets, there are issues that can prevent the compiler from applying certain optimizations. For each snippet: Circle the line number that contains compiler optimization blocker. ⚫ Select the best modification to improve optimization. 1. Which line prevents compiler optimization? Circle one: 2 3 4 5 6 Suggested solution: ⚫ Remove printf or move it outside the loop. Remove the loop. • Replace arr[i] with a constant value. 1 int sum (int *arr, int n) { 2 int s = 0; 3 for (int i = 0; i < n; i++) { 4 5 6 } 7 8 } s = arr[i]; printf("%d\n", s); return s; 234206 2. Which line prevents compiler optimization? Circle one: 2 3 4 5 6 Suggested solution: Move or eliminate do_extra_work() if it's not necessary inside the loop. Remove the loop (but what about scaling?). ⚫ Replace arr[i] *= factor; with arr[i] = 0; (why would that help?). 1 void scale (int *arr, int n, int factor) { 5 6 } for (int i = 0; i < n; i++) { rr[i] = factor; do_extra_work ();arrow_forward
- 123456 A ROP (Return-Oriented Programming) attack can be used to execute arbitrary instructions by chaining together small pieces of code called "gadgets." Your goal is to create a stack layout for a ROP attack that calls a function located at '0x4018bd3'. Below is the assembly code for the function 'getbuf', which allocates 8 bytes of stack space for a 'char' array. This array is then passed to the 'gets' function. Additionally, you are provided with five useful gadgets and their addresses. Use these gadgets to construct the stack layout. Assembly for getbuf 1 getbuf: sub mov $8, %rsp %rsp, %rdi call gets add $8, %rsp ret #Allocate 8 bytes for buffer #Load buffer address into %rdi #Call gets with buffer #Restore the stack pointer #Return to caller Stack Layout each 8-byte (fill in section) Address Value (8 bytes) 0x7fffffffdfc0 0x7fffffffdfb8 0x7fffffffdfb0 0x7fffffffdfa8 0x7fffffffdfa0 0x7fffffffdf98 0x7fffffffdf90 0x7fffffffdf88 Gadgets Address Gadget Ox4006a7 pop %rdi; ret Ox4006a9…arrow_forwardProblem 1 [15 points] The code below is buggy. Assume the code compiles. Briefly: 1). Identify the problem with the code (e.g., can access memory out of bounds) and 2). Suggest a solution (e.g., check the length). Question 1 1 #define BLENGTH 5 2 int b[BLENGTH]; 3 void copy_from_global_int_array_b (int n, int* dest) { 4 5 } *dest = b[n]; ==arrow_forwardWhich statement regarding SGA_MAX_SIZE is true? SGA_MAX_SIZE is modifiable after an instance is started, only when Automatic Memory Management is used. SGA_MAX_SIZE is not dyamically modifiable. SGA_MAX_SIZE is ignored when MEMORY_TARGET > 0. SGA-MAX_SIZE must be specified when SGA_TARGET > 0arrow_forward
- Explian this C program #include <stdio.h> unsigned int rotateRight(unsigned int num, unsigned int bits) { unsignedint bit_count =sizeof(unsignedint) *8; bits = bits % bit_count; // Handle cases where bits >= bit_count return (num >> bits) | (num << (bit_count - bits)); } int main() { unsignedint num, bits; printf("Enter a number: "); scanf("%u", &num); printf("Enter the number of bits to shift: "); scanf("%u", &bits); printf("After rotation: %u\n", rotateRight(num, bits)); return0; }arrow_forwardExplian thiS C program #include<stdio.h> int countSetBits(int n) { int count = 0; while (n) { count += n & 1; n >>= 1; } return count;} int main() { int num; printf("Enter a number: "); scanf("%d", &num); printf("Output: %d units\n", countSetBits(num)); return 0;}arrow_forwardPlease provide the Mathematica codearrow_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 LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning

Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,

C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage

Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning

Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning