All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
programming principles and practice
Questions and Answers of
Programming Principles and Practice
Modify class Link from §17.9.3 to be a template with the type of value as the template argument. Then redo exercise 13 from Chapter 17 with Link.
Why don’t we just always define a vector with a large enough size for all eventualities?
Write a template class Pair that can hold a pair of values of any type. Use this to implement a simple symbol table like the one we used in the calculator (§7.8).
Write a template function that takes a vector vt and a vector vu as arguments and returns the sum of all vt[i]*vu[i]s.
Write a template function f() that adds the elements of one vector to the elements of another; for example, f(v1,v2) should do v1[i]+=v2[i] for each element of v1.
What is a palindrome?
What is a C-style string?
When should you prefer a pointer argument over a reference argument? Why?
How do you initialize an array?
How do you copy an array?
Implement a version of the game “Hunt the Wumpus.” “Hunt the Wumpus” (or just “Wump”) is a simple (non-graphical) computer game originally invented by Gregory Yob. The basic premise is
What is an array?
Look up (e.g., on the web) skip list and implement that kind of list. This is not an easy exercise.
What operations may be invoked implicitly for a class object?
Look at the “array solution” to the palindrome problem in §18.7.2. Fix it to deal with long strings by (a) reporting if an input string was too long and (b) allowing an arbitrarily long string.
What is an explicit constructor? Where would you prefer one over the (default) alternative?
Consider the memory layout in §17.4. Write a program that tells the order in which static storage, the stack, and the free store are laid out in memory. In which direction does the stack grow:
What are the five “essential operations” for a class?
Rewrite all the functions in §18.7 to use the approach of making a backward copy of the string and then comparing; for example, take "home", generate "emoh", and compare those two strings to see
How does the copy of a vector compare to its source?
Write versions of the cat_dot()s from the previous exercises to take C-style strings as arguments and return a free-store-allocated C-style string as the result. Do not use standard library functions
What is shallow copy? What is deep copy?
Modify cat_dot() from the previous exercise to take a string to be used as the separator (rather than dot) as its third argument.Data from Previous ExerciseWrite a function, string cat_dot(const
What is the difference between copy assignment and copy initialization?
Write a function, string cat_dot(const string& s1, const string& s2), that concatenates two strings with a dot in between. For example, cat_ dot("Niels", "Bohr") will return a string
What is a copy assignment?
Consider what happens if you give strdup(), findx(), and strcmp() an argument that is not a C-style string. Try it! First figure out how to get a char* that doesn’t point to a zero-terminated array
What is a copy constructor?
Write a function, int strcmp(const char* s1, const char* s2), that compares C-style strings. Let it return a negative number if s1 is lexicographically before s2, zero if s1 equals s2, and a positive
When is the default meaning of copying of class objects appropriate?When is it inappropriate?
Write a function, char* findx(const char* s, const char* x), that finds the first occurrence of the C-style string x in s. Do not use any standard library functions. Do not use subscripting; use the
What is the default meaning of copying for class objects?
Write a function, char* strdup(const char*), that copies a C-style string into memory it allocates on the free store. Do not use any standard library functions. Do not use subscripting; use the
What does “Caveat emptor!” mean?
What is this and when do we need to use it?
What is a doubly-linked list?
How do we access a member of a class through a pointer?
What is a cast? When do we need to use one?
How are destructors for members called?
Could the “list of gods” example from §17.10.1 have been written using a singly-linked list; that is, could we have left the prev member out of Link? Why might we want to do that? For what kind
When do we want a virtual destructor?
Modify the Link class from §17.10.1 to hold a value of a struct God. struct God should have members of type string: name, mythology, vehicle, and weapon. For example, God{"Zeus", "Greek", "",
What is a destructor? When do we want one?
Why did we define two versions of find()?
When do we need a pointer (instead of a reference or a named object)?
Complete the “list of gods” example from §17.10.1 and run it.
What is a null pointer? When do we need to use one?
Look at your solution of exercise 7. Is there any way that input could get the array to overflow; that is, is there any way you could enter more characters than you allocated space for (a serious
How can we initialize a pointer?
Which way does the stack grow: up (toward higher addresses) or down (toward lower addresses)? Which way does the free store initially grow (that is, before you use delete)? Write a program to
What is a resource?
Do exercise 7 again, but this time read into a std::string rather than to memory you put on the free store (string knows how to use the free store for you).Data from Exercise 7Write a program that
What is a leak?
Write a program that reads characters from cin into an array that you allocate on the free store. Read individual characters until an exclamation mark (!) is entered. Do not use a std::string. Do not
What can a pointer point to?
This chapter does not say what happens when you run out of memory using new. That’s called memory exhaustion. Find out what happens. You have two obvious alternatives: look for documentation, or
What information about a pointed-to object does a pointer have? What useful information does it lack?
Write a function, char* findx(const char* s, const char* x), that finds the first occurrence of the C-style string x in s.
What is an address? How are memory addresses manipulated in C++?
Write a function, char* strdup(const char*), that copies a C-style string into memory it allocates on the free store. Do not use any standard library functions.
What is a dereference operator and why do we need one?
Write a function, void to_lower(char* s), that replaces all uppercase characters in the C-style string s with their lowercase equivalents. For example, Hello, World! becomes hello, world!. Do not use
What is the free store? What other name is commonly used for it? What operators support it?
How many bytes are there in an int? In a double? In a bool? Do not use sizeof except to verify your answer.
What four kinds of storage do we have for a typical program?
What is the output format of pointer values on your implementation?
Why do we need data structures with varying numbers of elements?
Why is debugging a GUI program harder than debugging an “ordinary program using streams for I/O”?
What is the basic strategy for debugging a GUI program?
What is control inversion?
When would you use a menu?
When would you use a button?
What is the type of the value stored in an inbox?
When would you use an inbox?
What are examples of widgets?
Which systems use the term widget and which prefer control?
What other GUI toolkits have you heard of?
Provide a program where you can choose among a set of functions (e.g., sin() and log()), provide parameters for those functions, and then graph them.
How do you pronounce FLTK?
Modify the calculator from Chapter 7 to get its input from an input box and return its results in an output box.
What does the acronym FLTK mean?
Provide a currency converter. Read the conversion rates from a file on startup. Enter an amount in an input window and provide a way of selecting currencies to convert to and from (e.g., a pair of
What is another name for widget?
Using the techniques developed in the previous exercises, make an image of an airplane “fly around” in a window. Have a “Start” and a “Stop” button.
What is a widget?
Make an “analog clock,” that is, a clock with hands that move. You get the time of day from the operating system through a library call. A major part of this exercise is to find the functions
Write a program that draws a shape of your choice and moves it to a new point each time you click “Next.” The new point should be determined by a coordinate pair read from an input stream.
What is the fundamental problem when communicating with an operating system from C++?
Make a menu with items that make a circle, a square, an equilateral triangle, and a hexagon, respectively. Make an input box (or two) for giving a coordinate pair, and place the shape made by
Why would you want to layer software?
Place an Image on top of a Button; move both when the button is pushed. Use this random number generator from std_lib_facilities.h to pick a new location for the “image button”:It returns a
What is a software layer?
Make a window (based on My_window) with a 4-by-4 checkerboard of square buttons. When pressed, a button performs a simple action, such as printing its coordinates in an output box, or turns a
When would you want a non-graphical user interface?
Make a My_window that’s a bit like Simple_window except that it has two buttons, next and quit.
Why would you want a graphical user interface?
How do you plan the general layout of a graph? How do you reflect that layout in your code?
Why would you format your input rather than just having the file contain “the numbers”?
How would you scale the input without trial and error?
How would you scale your graph so that the input will fit?
Showing 100 - 200
of 628
1
2
3
4
5
6
7