STARTING OUT WITH C++FROM CONTROL STRU
18th Edition
ISBN: 9781323815458
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9, Problem 22RQE
When a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Linux general memory layout includes stack, heap, data, and code.
stack memory relations stores local variables
heap: dynamic memory for programmer to allocate
data: stores global variables, separated into initialized and uninitialized
code: stores the code being executed
Use the following code to answer the questions that follow
#include <stdio.h>
#include <stdlib.h>
int x;
int main(int argc, char *argv[]) {
int y=3
printf(": %p\n", main);
int* z = malloc(100e6);
printf("location of stack: %p\n", &y);
return 0;
}
Where are the possible memory addresses of the above variables?
Address
Location
x
y
main
z
*z
C++
Create a class Student that contains three members: roll no, name and mark, and three functions. Write a first inputStudent() function to get data of student class. Write a second getMark() function that returns a student’s mark. Write a third display() function that displays a student’s data. In a main() function, you need to declare 40 students and get data of all students by using inputStudent() function. And also use a pointer array to keep all students by mark greater than 50 and display the searching data of each student in that pointer array (Use the access operator -> to access a pointer points to member functions of the Student class).
Assignment tasks:
Create a new file called pointerBasics.cpp. Write a C++ program in this new file. In this new file, write code that will do the following:
Declare an integer variable called myInt and assign the value 15 to it.
Declare a pointer variable called myPointer using the dereference operator (*) and assign it to the memory location of myInt using the address-of operator (&)
Print the memory location of myInt (remember the address-of operator!) and the value of myPointer.
Print the value of myInt and the value pointed to by myPointer (remember the dereference operator!)
Change the value of myInt to 10.
Print the memory location of myInt (remember the address-of operator!) and the value of myPointer.
Print the value of myInt and the value pointed to by myPointer (remember the dereference operator!)
(1 point) Declare and assign values to variables
(1 point) Print to console
(1 point) Change values and print to console
Take a screenshot of a sample output and…
Chapter 9 Solutions
STARTING OUT WITH C++FROM CONTROL STRU
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
What is the difference between a text file and a binary file?
Starting Out with Java: Early Objects (6th Edition)
Write Java code to display the largest and smallest values of type double that you can have in Java.
Java: An Introduction to Problem Solving and Programming (7th Edition)
Fill in the blanks in each of the following statements: A relation that has no partial functional dependencies ...
Modern Database Management
Describe the purpose of the access key attribute and how it supports accessibility.
Web Development and Design Foundations with HTML5 (8th Edition)
What is an algorithm?
Starting Out with Programming Logic and Design (4th Edition)
When a program is finished using a file, it should do this. a. erase the file b. open the file c. close the fil...
Starting Out with Python (3rd 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
- IN C++, TRUE OR FALSE : The statement delete p; deallocates the dynamic array that is pointed to by p. In the statement cin >> y;, y can only be an int or double variable. In an output statement, the newline character may be part of the string. The extraction operator (>>) skips whitespace characters when searching for the next data in the input stream.arrow_forwardstruct Info { int id; float cost; }; Given the struct above, the following code segment will correctly declare and initialize an instance of that struct. Info myInfo = {10,4.99}; Group of answer choices True False ============== Consider the following code fragment. int a[] = {3, -5, 7, 12, 9}; int *ptr = a; *ptr = (*ptr) + 1; cout << *ptr; Group of answer choices 4 -5 3 Address of -5 =============== What will happen if I use new without delete? Group of answer choices The program will never compile The program will never run The program will run fine without memory leak None of thesearrow_forwardC++ Part 1 Write a function that will receive a pointer to the address of the first element of the array. Read the ID numbers contained in idnumbers.txt into the array. Display a message which indicates that data is being read from the file. Return the number of elements saved in the array. Part 2 Write a function that will receive the pointer of the first element of an array, as well as the number of elements in the array. Display the contents of the array. Part 3 Write a function that will receive the pointer of the first element of an array, as well as the number of elements in the array. The function should display the birth date of each person. Assume valid years are from 1921-2020. Tip: The underscore character serves as the first locator character for each ID number, you can use this as a landmark to identify the indexes of each ID number. EXAMPLE OUTPUT List of ID…arrow_forward
- 7.10: Tic Tac Toe (sort of). (c++) Write a program that will allow two users to playtic-tac-toe. The program should ask for movesalternately from player X and player O. Theprogram displays the game positions as follows: 123 456 789 The players enter their moves by entering theposition number (a single digit, 1-9) theywish to mark. After eachmove, the program re-displays the changed board.A sample board configuration is as follows:XXO 456 O89 SAMPLE RUN #1: ./ETest Interactive Session 1 2 34 5 67 8 9 Enter move:1 X 2 34 5 67 8 9 Enter move:2 X O 34 5 67 8 9 Enter move:3 X O X4 5 67 8 9 Enter move:4 X O XO 5 67 8 9 Enter move:5 X O XO X 67 8 9 Enter move:6 X O XO X O7 8 9 Enter move:7 X O XO X OX 8 9 Enter move:8 X O XO X OX O 9 Enter move:9 X O XO X OX O X Game over!arrow_forwardPlease write in C display Pages 10. Write function display Pages to do the following a. Return type void b. Parameter list includes i. Parameter that contains the page number, data type integer (i.e., page)ii. One-dimensional array, data type integer, that stores the page allocations (i.e., allocation) c. Display to the console the page number d. Write a looping construct to iterate through the frames (i.e.. FRAMES) i. Display to the console the memory block assigned based on the following logic 1. If the value stored at the current index of array allocation is -1 (ie., INVALID), output a dash (i.e., *-*) 2. Else, output the allocation at the current index of array allocationarrow_forward(Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays so that a customer’s record can be accessed randomly by account number. Create the file by entering five customer records, with each record consisting of an integer account number (starting with account number 1000), a first name (maximum of 10 characters), a last name (maximum of 15 characters), and a double-precision number for the account balance. After the file is created, write a C++ program that requests a user-input account number and displays the corresponding name and account balance from the file.arrow_forward
- (Data processing) Write a C++ program that reads the file created in Exercise 4, permits the user to change the hourly wage or years for any employee, and creates a new updated file.arrow_forwardCreate a C++ Grocery Program according to this guideline: Linked List Functions Pointers Arrays The program must have a menu layout where the user can select certain action (Select Product, View My Cart, Check-Out, etc.) You must include all kinds of drinks/beverages Implement basic error tapping IYou must include the group name of the developers with the name of each developer (a total of 4) Group Name: In-Out Group Names: Cesar Rachel Jennifer Tomarrow_forwardStarter Code #include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#include <stdlib.h> #include <iostream> #include <pthread.h>#include <semaphore.h>#include <atomic> using namespace std; // The length of time the program should runint run_time; // The buffer that will be produced into and consumed from. int *buffer;int buffer_size; // The number of producers and consumers we will haveint num_producers;int num_consumers; // TODO: Declare the semaphores that you will need to implement this algorithm// Semaphores are of type sem_t // TODO: Declare a mutex that you will use in your implementation.// Use type pthread_mutex_t // TODO: Declare any other global variables you will need to // use to implement your algorithm // These atomic variables will be used simply to generate unique numbers// to identify each thread.atomic_int producer_num(0);atomic_int consumer_num(0); // This is the function that will be…arrow_forward
- Complete the program below by implementing the following tasks: Create a pointer called numberOfFlightsPtr that "points" to numberOfFlights Create another pointer called costPerFlightPtr that "points" to costPerFlight Create a function called calculateCost that computes and returns the product of two pointers Print out the total cost of flights (using your function created in #3) Create a function that dynamically creates a double array of size 10 on the heap. Then set each item in the array to an initial value of 5.0. Your function should then return a pointer to the first element of you dynamically allocated array.arrow_forwardThe next two problems introduce command-line arguments. Command-line arguments are commonly used in console-based applications. They afford the operator the ability to execute a program by passing in arguments from the command line. We need add two arguments to our main() The first argument is an int that contains the number of command line arguments, the second argument is an array of char pointers, which contain the actual command line arguments. The command line argument values are stored in an array, and can be accessed to perform different tasks. The first command line argument, argv[0] is always the name of the executable file. The remaining arguments can be accessed by indexing into the array. For example, the next argument would be located in argv[1]. When writing programs with command line arguments, it is important to clarify the program’s usage. This way the operator knows how to execute the program with the correct arguments. Here is an example program where the user enters…arrow_forwardC++ Assume the following declaration: vector<int>* ages; Which statement is syntactically correct? Only consider a successful compile, not including a possible a runtime error. A. ages.push_back(78); B. cout << ages.size(); C. ages = new vector<bool*>; D. delete ages; E. None of the above statements are syntactically correct.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
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
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License