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
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
programming principles and practice
Questions and Answers of
Programming Principles and Practice
What does isalnum(c) do?
When would you prefer line-oriented input to type-specific input?
Write a program to read a file of whitespace-separated numbers and output them in order (lowest value first), one value per line. Write a value only once, and if it occurs more than once write the
What happens if you position a file position beyond the end of file?
Write a program that reads a file of whitespace-separated numbers and outputs a file of numbers using scientific format and precision 8 in four fields of 20 characters per line.
What is a file position?
Write a program that reads a text file and writes out how many characters of each character classification (§11.6) are in the file.
Give two examples where a stringstream can be useful.
Define a Roman_int class for holding Roman numerals (as ints) with a << and >>. Provide Roman_int with an as_int() member that returns the int value, so that if r is a Roman_int, we can
Write a program that reads the data from raw_temps.txt created in exercise 2 into a vector and then calculates the mean and median temperatures in your data set. Call this program temp_stats.cpp.Data
What can a function declaration consist of?
When do we consider a program finished?
What should be in comments and what should not?
When would you not test a post-condition?
Reverse the order of words (defined as whitespace-separated strings) in a file. For example, Norwegian Blue parrot becomes parrot Blue Norwegian. You are allowed to assume that all the strings from
Give an example of when it would probably be beneficial to use a binary file instead of a text file.
Reverse the order of characters in a text file. For example, asdfghjkl becomes lkjhgfdsa. Warning: There is no really good, portable, and efficient way of reading a file backward.
What is the difference between character I/O and binary I/O?
Write a function vector split(const string& s, const string& w) that returns a vector of whitespace-separated substrings from the argument s, where whitespace is defined as “ordinary
Write a function vector split(const string& s) that returns a vector of whitespace-separated substrings from the argument s.
Split the binary I/O program from §11.3.2 into two: one program that converts an ordinary text file into binary and one program that reads binary and converts it to text. Test these programs by
Use the program from the previous exercise to make a dictionary (as an alternative to the approach in §11.7). Run the result on a multi-page text file, look at the result, and see if you can improve
Modify the program from the previous exercise so that it replaces don't with do not, can't with cannot, etc.; leaves hyphens within words intact (so that we get “ do not use the as-if rule ”);
Write a program that replaces punctuation with whitespace. Consider . (dot), ; (semicolon), , (comma), ? (question mark), - (dash), ' (single quote) punctuation characters. Don’t modify characters
Write a program that reads strings and for each string outputs the character classification of each character, as defined by the character classification functions presented in §11.6. Note that a
Write a program called multi_input.cpp that prompts the user to enter several integers in any combination of octal, decimal, or hexadecimal, using the 0 and 0x base suffixes; interprets the numbers
Write a program that removes all vowels from a file (“disemvowels”). For example, Once upon a time! becomes nc pn tm!. Surprisingly often, the result is still readable; try it on your friends.
Write a program that given a file name and a word outputs each line that contains that word together with the line number.
Write a program that reads a text file and converts its input to all lower case, producing a new file.
What are the usual function declarations for << and >> for a user-defined type X?
What are the two most common uses of the istream member function clear()?
Why do we (often) want to separate input and output from computation?
In what way is output usually harder than input?
Write a program that produces the sum of all the whitespace-separated integers in a text file. For example, bears: 17 elephants 9 end should output 26.
In what way is input usually harder than output?
Add a command from x to the calculator from Chapter 7 that makes it take input from a file x. Add a command to y to the calculator that makes it write its output (both standard output and error
Discuss how the following input problems can be resolved:a. The user typing an out-of-range valueb. Getting no value (end of file)c. The user typing something of the wrong type
Write a program that takes two files containing sorted whitespace-separated words and merges them, preserving order.
Write a program that accepts two file names and produces a new file that is the contents of the first file followed by the contents of the second; that is, the program concatenates the two files.
Make a version of the calculator from Chapter 7 that accepts Roman numerals rather than the usual Arabic ones, for example, XXI + CIV == CXXV.
Write the function print_year() mentioned in §10.11.2.
Modify the store_temps.cpp program from exercise 2 to include a temperature suffix c for Celsius or f for Fahrenheit temperatures. Then modify the temp_stats.cpp program to test each temperature,
Write a program that creates a file of data in the form of the temperature Reading type defined in §10.5. For testing, fill the file with at least 50 “temperature readings.” Call this program
Write a program that produces the sum of all the numbers in a file of whitespace-separated integers.
Give an example of a calculation where a Rational gives a mathematically better result than double.
Give an example of a calculation where a Rational gives a mathematically better result than Money.
Define an input operator (>>) that reads monetary amounts with currency denominations, such as USD1.23 and DKK5.00, into a Money variable. Also define a corresponding output operator (<<).
Refine the Money class by adding a currency (given as a constructor argument). Accept a floating-point initializer as long as it can be exactly represented as a long int. Don’t accept illegal
Design and implement a Money class for calculations involving dollars and cents where arithmetic has to be accurate to the last cent using the 4/5 rounding rule (.5 of a cent rounds up; anything less
Design and implement a rational number class, Rational. A rational number has two parts: a numerator and a denominator, for example, 5/6 (five-sixths, also known as approximately .83333). Look up the
Change the representation of a Date to be the number of days since January 1, 1970 (known as day 0), represented as a long int, and re-implement the functions from §9.8. Be sure to reject dates
Design and implement a set of useful helper functions for the Date class with functions such as next_workday() (assume that any day that is not a Saturday or a Sunday is a workday) and week_of_year()
Implement leapyear() from §9.8.
Why are “helper functions” best placed outside the class definition?
Create a Library class. Include vectors of Books and Patrons. Include a struct called Transaction. Have it include a Book, a Patron, and a Date from the chapter. Make a vector of Transactions. Create
What does adding const to a member function do?
Create a Patron class for the library. The class will have a user’s name, library card number, and library fees (if owed). Have functions that access this data, as well as a function to set the fee
Why should the public interface to a class be as small as possible?
Create an enumerated type for the Book class called Genre. Have the types be fiction, nonfiction, periodical, biography, and children. Give each book a Genre and make appropriate changes to the Book
When should operator overloading be used in a program? Give a list of operators that you might want to overload (each with a reason).
Add operators for the Book class. Have the == operator check whether the ISBN numbers are the same for two books. Have != also compare the ISBN numbers. Have a << print out the title, author,
When should functions be put in the class definition, and when should they be defined outside the class? Why?
This exercise and the next few require you to design and implement a Book class, such as you can imagine as part of software for a library. Class Book should have members for the ISBN, title, author,
What is an invariant? Give examples.
Look at the headache-inducing last example of §8.4. Indent it properly and explain the meaning of each construct. Note that the example doesn’t do anything meaningful; it is pure obfuscation.
Why is a constructor used for the Date type instead of an init_day() function?
Replace Name_pair::print() with a (global) operator << and define == and != for Name_pairs.
Design and implement a Name_pairs class holding (name,age) pairs where name is a string and age is a double. Represent that as a vector (called name) and a vector (called age) member. Provide an
List sets of plausible operations for the examples of real-world objects in §9.1 (such as toaster).
What is namespace std?
Why should you avoid using directives in a header?
What is a using declaration?
How does a namespace differ from a class?
What is the purpose of a namespace?
What is a call stack and why do we need one?
What goes into an activation record?
Which of the following is standard-conforming C++: functions within functions, functions within classes, classes within classes, classes within functions?
What do x&&y and x||y, respectively, mean?
Give an example of undefined order of evaluation. Why can undefined order of evaluation be a problem?
Would you ever define a function with a vector-by-value parameter?
What is a swap()?
What is the difference between pass-by-reference and pass-by-const-reference?
Can we declare a non-reference function argument const (e.g., void f(const int);)? What might that mean? Why might we want to do that? Why don’t people do that often? Try it; write a couple of
What is the difference between pass-by-value and pass-by-reference?
Write a function that takes a vector argument and returns a vector containing the number of characters in each string. Also find the longest and the shortest string and the lexicographically first
Why should a programmer minimize the number of global variables?
Improve print_until_s() from §8.5.2. Test it. What makes a good set of test cases? Give reasons. Then, write a print_until_ss() that prints until it sees a second occurrence of its quit argument.
What is the difference between a class scope and local scope?
Write a function that finds the smallest and the largest element of a vector argument and also computes the mean and the median. Do not use global variables. Either return a struct containing the
What kinds of scope are there? Give an example of each.
Write a function maxv() that returns the largest element of a vector argument.
What is the scope of a declaration?
Write a function that given two vectors price and weight computes a value (an “index”) that is the sum of all price[i]*weight[i]. Make sure to have weight.size()==price.size().
What are header files used for?
Then, do that exercise again but allowing an arbitrary number of names.
What good does indentation do?
Read five names into a vector name, then prompt the user for the ages of the people named and store the ages in a vector age. Then print out the five (name[i],age[i]) pairs. Sort the nam
Write versions of the functions from exercise 5, but with a vector.Data from Exercise 5Write two functions that reverse the order of elements in a vector. For example, 1, 3, 5, 7, 9 becomes 9, 7, 5,
Why is it a good idea to initialize variables as they are declared?
Write two functions that reverse the order of elements in a vector. For example, 1, 3, 5, 7, 9 becomes 9, 7, 5, 3, 1. The first reverse function should produce a new vector with the reversed
Showing 300 - 400
of 628
1
2
3
4
5
6
7