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
Is int a; a definition or just a declaration?
An int can hold integers only up to a maximum number. Find an approximation of that maximum number by using fibonacci().
Why can’t you use the functions in the calculator program from Chapter 6 without declaring them first?
Create a vector of Fibonacci numbers and print them using the function from exercise 2. To create the vector, write a function, fibonacci(x,y,v,n), where integers x and y are ints, v is an empty
How do we syntactically distinguish between a variable declaration and a variable definition?
Write a function print() that prints a vector of ints to cout. Give it two arguments: a string for “labeling” the output and a vector.
How do we syntactically distinguish between a function declaration and a function definition?
Modify the calculator program from Chapter 7 to make the input stream an explicit parameter (as shown in §8.5.8), rather than simply using cin. Also give the Token_stream constructor (§7.8.2) an
What is the difference between a declaration and a definition?
Why do you add comments?
How do you choose names for variables and functions? List possible reasons.
How do you decide what should be a separate function?
When do you retest?
When do you start to test?
Why is it a good idea to build a program incrementally?
What are the rules for what names can and cannot be in the calculator program?
The input representation for let is more than one character. How is it accepted as a single token in the modified code?
Revisit two programs you wrote for the exercises in Chapter 4 or 5. Clean up that code according to the rules outlined in this chapter. See if you find any bugs in the process.
What does is_declared() do and how does it work?
Modify the calculator to operate on ints (only); give errors for overflow and underflow.
How do we handle % (remainder) of floating-point numbers?
Suggest three improvements to the calculator. Implement one of them.
Why do we care about code layout?
The grammar in §7.6.4 is incomplete (we did warn you against overreliance on comments); it does not define sequences of statements, such as 4+4; 5–6;, and it does not incorporate the grammar
What is the use of symbolic constants?
Change the q and h commands to be quit and help, respectively.
What does narrow_cast do?
Part of what every program should do is to provide some way of helping its user. Have the calculator print out some instructions for how to use the calculator if the user presses the H key (both
What is the purpose of commenting and how should it be done?
Modify Token_stream::get() to return Token(print) when it sees a newline. This implies looking for whitespace characters and treating newline ('\n') specially. You might find the standard library
Why do we split code into multiple functions? State principles.
The get_value(), set_value(), is_declared(), and define_name() functions all operate on the variable var_table. Define a class called Symbol_table with a member var_table of type vector and member
We split main() into two separate functions. What does the new function do and why did we split main()?
Provide named constants that you really can’t change the value of. You have to add a member to Variable that distinguishes between constants and variables and check for it in set_value(). If you
Why did we choose to make a constant character called number?
Provide an assignment operator, =, so that you can change the value of a variable after you introduce it using let. Discuss why that can be useful and how it can be a source of problems.
Why does 1+2; q typed into the calculator not quit after it receives an error?
Allow underscores in the calculator’s variable names.
What is the purpose of working on the program after the first version works? Give a list of reasons.
Why do we want to rely on libraries of code?
What is the interface to a C++ “user-defined type”?
What is a “user-defined type”? Why would we want one?
When should we start testing our program?
Why were the ';' and 'q' characters added to the switch-statement in the get() function of the Token_stream class?
What happens in the Token_stream class when there is a token in the buffer and the get() function is called?
Why do we (sometimes) split a class’s members into private and public members?
What do we use the two data members of the Token class for?
Why is the remainder (modulus) operation, %, difficult to implement in the term()?
What does putback() do and why is it useful?
What is “look-ahead”?
A permutation is an ordered subset of a set. For example, say you wanted to pick a combination to a vault. There are 60 possible numbers, and you need three different numbers for the combination.
Write a program that reads digits and composes them into integers. For example, 123 is read as the characters 1, 2, and 3. The program should output 123 is 1 hundred and 2 tens and 3 ones. The number
Redo the “Bulls and Cows” game from exercise 12 in Chapter 5 to use four letters rather than four digits.Data from Exercise 5Implement a little guessing game called (for some obscure reason)
Write a grammar for bitwise logical expressions. A bitwise logical expression is much like an arithmetic expression except that the operators are ! (not), ~ (complement), & (and), | (or), and ^
Write a program that checks if a sentence is correct according to the “English” grammar in §6.4.1. Assume that every sentence is terminated by a full stop (.) surrounded by whitespace. For
Add the article the to the “English” grammar in §6.4.1, so that it can describe sentences such as “The birds fly but the fish swim.”
Define a class Name_value that holds a string and a value. Rework exercise 19 in Chapter 4 to use a vector instead of two vectors.Dara from Exercise 19Write a program where you first enter a set of
Add a factorial operator: use a suffix ! operator to represent “factorial.” For example, the expression 7! means 7 * 6 * 5 * 4 * 3 * 2 * 1. Make ! bind tighter than * and /; that is, 7*8! means
Add the ability to use {} as well as () in the program, so that {(4+5)*6} / (3+4) will be a valid expression.
How does testing differ from debugging?
Why does commenting help when debugging?
What are the steps in debugging a program?
When would you not test a pre-condition?
Define pre-condition and post-condition; give an example (that is not the area() function from this chapter), preferably a computation that requires a loop.
Why, with a vector called v, is v[v.size()] a range error? What would be the result of calling this?
Describe the process of how exceptions are thrown and caught.
Read (day-of-the-week,value) pairs from standard input. For example: Tuesday 23 Friday 56 Tuesday –3 Thursday 99Collect all the values for each day of the week in a vector. Write out
How do you test if an input operation succeeded?
The program is a bit tedious because the answer is hard-coded into the program. Make a version where the user can play repeatedly (without stopping and restarting the program) and each game has a new
Why is using exceptions a better idea than returning an “error value”?
Implement a little guessing game called (for some obscure reason) “Bulls and Cows.” The program has a vector of four different integers in the range 0 to 9 (e.g., 1234 but not 1122) and it is the
Compare and contrast having the caller of a function handle a run-time error vs. the called function’s handling the run-time error.
Write a program that writes out the first so many values of the Fibonacci series, that is, the series that starts with 1 1 2 3 5 8 13 21 34. The next number of the series is the sum of the two
How do you know if a result is plausible? What techniques do you have to answer such questions?
Modify the program from exercise 8 to use double instead of int. Also, make a vector of doubles containing the N–1 differences between adjacent values and write out that vector of differences.Data
List four potential sources of program errors discussed in the text.
Modify the program from exercise 8 to write out an error if the result cannot be represented as an int.Data from Exercise 8Write a program that reads and stores a series of integers and then computes
What is a logic error? Give three examples.
Write a program that reads and stores a series of integers and then computes the sum of the first N integers. First ask for N, then read the values into a vector, then calculate the sum of the first
What is a linker error? Give three examples.
Quadratic equations are of the forma ⋅ x2 + b ⋅ x + c = 0To solve these, one uses the quadratic formula:There is a problem, though: if b2–4ac is less than zero, then it will fail. Write a
What is a type error? Give five examples.
Write a program that converts from Celsius to Fahrenheit and from Fahrenheit to Celsius (formula in §4.3.3). Use estimation (§5.8) to see if your results are plausible.
What is a syntax error? Give five examples.
Add to the program so that it can also convert from Kelvin to Celsius.
Why do we hate debugging?
Do exercise 3 again, but this time handle the error inside ctok().Dara from Exercise 3Absolute zero is the lowest temperature that can be reached; it is –273.15°C, or 0K. The above program, even
List three approaches we can take to eliminate errors in programs and produce acceptable software.
Absolute zero is the lowest temperature that can be reached; it is –273.15°C, or 0K. The above program, even when corrected, will produce erroneous results when given a temperature below this.
What guarantees should every completed project offer?
The following program takes in a temperature value in Celsius and converts it to Kelvin. This code has many errors in it. Find the errors, list them, and correct the code. double ctok(double c) /l
What kinds of errors can we ignore in student programs?
If you haven’t already, do the Try this exercises from this chapter.
Name four major types of errors and briefly define each one.
Do exercise 6, but with three string values. So, if the user enters the values Steinbeck, Hemingway, Fitzgerald, the output should be Fitzgerald, Hemingway, Steinbeck.
Modify the program above to ask the user to enter floating-point values and store them in double variables. Compare the outputs of the two programs for some inputs of your choice. Are the results the
How do you sort the elements of a vector?
What makes vector so popular/useful?
What does vector’s member size() do?
Describe what push_back() does to a vector.
Showing 400 - 500
of 628
1
2
3
4
5
6
7