
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 13.6, Problem 13.8CP
What is a class specification file? What is a class implementation file?
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these 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 }
Match 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
}
ret
Given 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. *p4
Chapter 13 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 13.3 - True or False: You must declare all private...Ch. 13.3 - Assume RetailItem is the name of a class, and the...Ch. 13.3 - An objects private member variables are accessed...Ch. 13.3 - Assume RetailItem is the name of a class, and the...Ch. 13.3 - Complete the following code skeleton to declare a...Ch. 13.6 - Why would you declare a classs member variables...Ch. 13.6 - When a classs member variables are declared...Ch. 13.6 - What is a class specification file? What is a...Ch. 13.6 - Prob. 13.9CPCh. 13.6 - Assume the following class components exist in a...
Ch. 13.6 - What is an inline member function?Ch. 13.9 - Briefly describe the purpose of a constructor.Ch. 13.9 - Prob. 13.13CPCh. 13.9 - A member function that is never declared with a...Ch. 13.9 - A member function that is never declared with a...Ch. 13.9 - Prob. 13.16CPCh. 13.9 - A constructor that requires no arguments is called...Ch. 13.9 - True or False: Constructors are never declared...Ch. 13.9 - True or False: Destructors are never declared with...Ch. 13.9 - Prob. 13.20CPCh. 13.12 - What will the following program display on the...Ch. 13.12 - What will the following program display on the...Ch. 13.12 - In your answer for Checkpoint 13.22, indicate for...Ch. 13.12 - Why would a member function be declared private?Ch. 13.12 - Define an array of three InventoryItem objects.Ch. 13.12 - Complete the following program so it defines an...Ch. 13.16 - Prob. 13.27CPCh. 13.16 - When designing an object-oriented application, who...Ch. 13.16 - How do you identify the potential classes in a...Ch. 13.16 - What are a classs responsibilities?Ch. 13.16 - What two questions should you ask to determine a...Ch. 13.16 - Will all of a classs actions always be directly...Ch. 13.16 - Look at the following description of a problem...Ch. 13 - What is the difference between a class and an...Ch. 13 - What is the difference between the following...Ch. 13 - What is the default access specification of class...Ch. 13 - Look at the following function header for a member...Ch. 13 - A contractor uses a blueprint to build a set of...Ch. 13 - What is a mutator function? What is an accessor...Ch. 13 - Is it a good idea to make member variables...Ch. 13 - Can you think of a good reason to avoid writing...Ch. 13 - Under what circumstances should a member function...Ch. 13 - What is a constructor? What is a destructor?Ch. 13 - What is a default constructor? Is it possible to...Ch. 13 - Is it possible to have more than one constructor?...Ch. 13 - If a class object is dynamically allocated in...Ch. 13 - When defining an array of class objects, how do...Ch. 13 - What are a classs responsibilities?Ch. 13 - How do you identify the classes in a problem...Ch. 13 - Programming: In programming, there are two most...Ch. 13 - ____________ programming is centered around...Ch. 13 - _________ programming is centered around objects.Ch. 13 - _____________ is an objects ability to contain and...Ch. 13 - In C++, the _________ is the construct primarily...Ch. 13 - A class is very similar to a(n) _____________.Ch. 13 - A(n) _________ is a key word inside a class...Ch. 13 - The default access specification of class members...Ch. 13 - The default access specification of a struct in...Ch. 13 - Defining a class object is often called the...Ch. 13 - Members of a class object may be accessed through...Ch. 13 - If you were writing the declaration of a class...Ch. 13 - If you were writing the external definitions of...Ch. 13 - When a member functions body is written inside a...Ch. 13 - A(n) __________ is automatically called when an...Ch. 13 - A(n) __________ is a member function with the same...Ch. 13 - __________ are useful for performing...Ch. 13 - Constructors cannot have a(n) _________ type.Ch. 13 - A(n) ___________ constructor is one that requires...Ch. 13 - A(n) ___________ is a member function that is...Ch. 13 - A destructor has the same name as the class, but...Ch. 13 - Like constructors, destructors cannot have a(n)...Ch. 13 - A constructor whose arguments all have default...Ch. 13 - A class may have more than one constructor, as...Ch. 13 - Prob. 41RQECh. 13 - A(n) __________ may be used to pass arguments to...Ch. 13 - Write a class declaration named Circle with a...Ch. 13 - Add a default: constructor to the Circle class in...Ch. 13 - Add an overloaded constructor to the Circle class...Ch. 13 - Write a statement that defines an array of five...Ch. 13 - Write a statement that defines an array of five...Ch. 13 - Prob. 48RQECh. 13 - If the items on the following list appeared in a...Ch. 13 - Look at the following description of a problem...Ch. 13 - T F Private members must be declared before public...Ch. 13 - T F Class members are private by default.Ch. 13 - T F Members of a struct are private by default.Ch. 13 - T F Classes and structures in C++ are very...Ch. 13 - T F All private members of a class must be...Ch. 13 - T F All public members of a class must be declared...Ch. 13 - T F It is legal to define a pointer to a class...Ch. 13 - T F You can use the new operator to dynamically...Ch. 13 - T F A private member function may be called from a...Ch. 13 - T F Constructors do not have to have the same name...Ch. 13 - T F Constructors may not have a return type.Ch. 13 - T F Constructors cannot take arguments.Ch. 13 - T F Destructors cannot take arguments.Ch. 13 - T F Destructors may return a value.Ch. 13 - T F Constructors may have default arguments.Ch. 13 - T F Member functions may be overloaded.Ch. 13 - T F Constructors may not be overloaded.Ch. 13 - T FA class may not have a constructor with no...Ch. 13 - T F A class may only have one destructor.Ch. 13 - T F When an array of objects is defined, the...Ch. 13 - T F To find the classes needed for an...Ch. 13 - T F A classs responsibilities are the things the...Ch. 13 - class Circle: { private double centerX; double...Ch. 13 - #include iostream using namespace std; Class Moon;...Ch. 13 - #inc1ude iostream using namespace std; class...Ch. 13 - class Change { public: int pennies; int nickels;...Ch. 13 - Date Design a class called Date. The class should...Ch. 13 - Employee Class Write a class named Employee that...Ch. 13 - Car Class Write a class named Car that has the...Ch. 13 - Patient Charges Write a class named Patient that...Ch. 13 - Retail Item Class Write a class named RetailItem...Ch. 13 - Inventor Class Design an Inventory class that can...Ch. 13 - TestScores Class Design a TestScores class that...Ch. 13 - Circle Class Write a Circle class that has the...Ch. 13 - Population In a population, the birth rate and...Ch. 13 - Number Array Class Design a class that has an...Ch. 13 - Payroll Class Design a PayRoll class that has data...Ch. 13 - Coin Toss Simulator Write a class named Coin. The...Ch. 13 - Tossing Coins for a Dollar For this assignment,...Ch. 13 - Fishing Game Simulation For this assignment, you...Ch. 13 - Mortgage Payment Design a class that will...Ch. 13 - Freezing and Boiling Points The following table...Ch. 13 - Cash Register Design a CashRegister class that can...Ch. 13 - A Game of 21 For this assignment, you will write a...Ch. 13 - Trivia Game In this programming challenge, you...Ch. 13 - Patient Fees 1. This program should be designed...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Determine the moment reactions at the supports A and B. El is constant.
Mechanics of Materials (10th Edition)
Assume the following variable declaration exists in a program: double number = 123.456; Write a statement that ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Can you use the method add to insert an element at a position for which you cannot use set?
Java: An Introduction to Problem Solving and Programming (8th Edition)
(Multiples of 2 with an Infinite Loop) Write an application that keeps displaying in the command window the mul...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
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)
What is pseudocode?
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
- 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
- Explian this C program code. #include <stdio.h> void binary(unsigned int n) { if (n /2!=0) { binary(n /2); } printf("%d", n %2); } int main() { unsignedint number =33777; unsignedchar character ='X'; printf("Number: %u\n", number); printf("Binary: "); binary(number); printf("\nDecimal: %u\nHexadecimal: 0x%X\n\n", number, number); printf("Character: %c\n", character); printf("ASCII Binary: "); binary(character); printf("\nASCII Decimal: %u\nASCII Hexadecimal: 0x%X\n", character, character); return0; }arrow_forwardDesign a dynamic programming algorithm for the Longest Alternating Subsequence problem described below: Input: A sequence of n integers Output: The length of the longest subsequence where the numbers alternate between being larger and smaller than their predecessor The algorithm must take O(n²) time. You must also write and explain the recurrence. Example 1: Input: [3, 5, 4, 1, 3, 6, 5, 7, 3, 4] Output: 8 ([3, 5, 4, 6, 5, 7, 3, 4]) Example 2: Input: [4,7,2,5,8, 3, 8, 0, 4, 7, 8] Output: 8 ([4, 7, 2, 5, 3, 8, 0,4]) (Take your time with this for the subproblem for this one)arrow_forwardDesign a dynamic programming algorithm for the Coin-change problem described below: Input: An amount of money C and a set of n possible coin values with an unlimited supply of each kind of coin. Output: The smallest number of coins that add up to C exactly, or output that no such set exists. The algorithm must take O(n C) time. You must also write and explain the recurrence. Example 1: Input: C24, Coin values = = [1, 5, 10, 25, 50] Output: 6 (since 24 = 10+ 10+1+1 +1 + 1) Example 2: Input: C = 86, Coin values = [1, 5, 6, 23, 35, 46, 50] Output: 2 (since 86 = 46+35+5)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 LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems 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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT

EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT

C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr

Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher: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