New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
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
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
programming principles and practice
Programming Principles And Practice Using C++ 2nd Edition Bjarne Stroustrup - Solutions
What does vector alphabet(26); do?
How do you write a for-loop that prints every element of a vector?
What is the index of the third element of a vector?
What can you do to a string that you cannot do to an int?
Modify the program from exercise 19 so that when you enter an integer, the program will output all the names with that score or score not found.Dara from Exercise 19Write a program where you first enter a set of name-and-value pairs, such as Joe 17 and Barbara 22. For each pair, add the name to a
What can you do to an int that you cannot do to a string?
Modify the program from exercise 19 so that when you enter a name, the program will output the corresponding score or name not found.Dara from Exercise 19Write a program where you first enter a set of name-and-value pairs, such as Joe 17 and Barbara 22. For each pair, add the name to a vector
When should you define a separate function for part of a program? List reasons.
Write a program where you first enter a set of name-and-value pairs, such as Joe 17 and Barbara 22. For each pair, add the name to a vector called names and the number to a vector called scores (in corresponding positions, so that if names[7]=="Joe" then scores[7]==17). Terminate input with NoName
Describe what the line char foo(int x) means in a function definition.
Write a program to solve quadratic equations. A quadratic equation is of the formax2 + bx + c = 0If you don’t know the quadratic formula for solving such an expression, do some research. Remember, researching how to solve a problem is often necessary before a programmer can teach the computer how
How do you print the numeric value of a char?
Write a program that finds the min, max, and mode of a sequence of strings.
When should the for-loop be used and when should the while-loop be used?
In the drill, you wrote a program that, given a series of numbers, found the max and min of that series. The number that appears the most times in a sequence is called the mode. Create a program that finds the mode of a set of positive integers.
What is the function of each part of the header line in a for-loop, and in what sequence are they executed?
Write a program that takes an input value n and then finds the first n primes.
What are some common problems with switch-statements?
Modify the program described in the previous exercise to take an input value max and then find all prime numbers from 1 to max.Data from Previous ExerciseCreate a program to find all the prime numbers between 1 and 100. There is a classic method for doing this, called the “Sieve of
When would a programmer prefer a switch-statement to an if-statement?
Create a program to find all the prime numbers between 1 and 100. There is a classic method for doing this, called the “Sieve of Eratosthenes.” If you don’t know that method, get on the web and look it up. Write your program using this method.
What are some operators that can be used for strings?
Modify the program described in the previous exercise to take an input value max and then find all prime numbers from 1 to max.Data from Previous ExerciseCreate a program to find all the prime numbers between 1 and 100. One way to do this is to write a function that will check if a number is prime
What operators can be used on integers but not on floating-point numbers?
Create a program to find all the prime numbers between 1 and 100. One way to do this is to write a function that will check if a number is prime (i.e., see if the number can be divided by a prime number smaller than itself) using a vector of primes in order (so that if the vector is called primes,
What are some operators that we can use for integers and floating-point values?
Write a program that plays the game “Rock, Paper, Scissors.” If you are not familiar with the game do some research (e.g., on the web using Google). Research is a common task for programmers. Use a switch-statement to solve this exercise. Also, the machine should give random answers (i.e.,
What is a magic constant? Give examples.
Try to calculate the number of rice grains that the inventor asked for in exercise 8 above. You’ll find that the number is so large that it won’t fit in an int or a double. Observe what happens when the number gets too large to represent exactly as an int and as a double. What is the largest
What is a symbolic constant and why do we use them?
There is an old story that the emperor wanted to thank the inventor of the game of chess and asked the inventor to name his reward. The inventor asked for one grain of rice for the first square, 2 for the second, 4 for the third, and so on, doubling for each of the 64 squares. That may sound
What is a literal?
Modify the “mini calculator” from exercise 5 to accept (just) single-digit numbers written as either digits or spelled out.Data from Exercise 5Write a program that performs as a very simple calculator. Your calculator should be able to handle the four basic math operations — add, subtract,
What is a constant expression?
Make a vector holding the ten string values "zero", "one", . . . "nine". Use that in a program that converts a digit to its corresponding spelled-out value; e.g., the input 7 gives the output seven. Have the same program, using the same input loop, convert spelled-out numbers into their digit form;
What is an lvalue? List the operators that require an lvalue. Why do these operators, and not the others, require an lvalue?
Write a program that performs as a very simple calculator. Your calculator should be able to handle the four basic math operations — add, subtract, multiply, and divide — on two input values. Your program should prompt the user to enter three arguments: two double values and a character to
What is the difference between a statement and an expression, as described in this chapter?
Write a program to play a numbers guessing game. The user thinks of a number between 1 and 100 and your program asks questions to figure out what the number is (e.g., “Is the number you are thinking of less than 50?”). Your program should be able to identify the number after asking no more than
What does an expression do?
Read a sequence of double values into a vector. Think of each value as the distance between two cities along a given route. Compute and print the total distance (the sum of all distances). Find and print the smallest and greatest distance between two neighboring cities. Find and print the mean
What are the three requirements a programmer should keep in mind when expressing computations?
If we define the median of a sequence as “a number so that exactly as many elements come before it in the sequence as come after it,” fix the program in §4.6.3 so that it always prints out a median. Hint: A median need not be an element of the sequence.
What do we mean by inputs and outputs to a computation? Give examples.
From a philosophical point of view, you can now do everything that can be done using a computer — the rest is details! Among other things, this shows the value of “details” and the importance of practical skills, because clearly you have barely started as a programmer. But we are serious. The
If you haven’t already, do the Try this exercises from this chapter.
What is a computation?
Define a rule to help decide if a conversion from one type to another is safe or unsafe.
Why can conversion from double to int be a bad thing?
What is type safety and why is it important?
What are some good rules for choosing names?
Give five examples of legal names that you shouldn’t use because they are likely to cause confusion.
Which of the following are legal names in C++? If a name is not legal, why not? This_little_pig latest thing This 1_is fine the_$12_method 2_For_1_special _this_is_ok MiniMineMine number correct?
What is string concatenation and how do you make it work in C++?
What is an initialization and how does it differ from an assignment?
What is a definition?
What measures do we use for the size of small entities in memory, such as ints and strings?
What are typical sizes for a char, an int, and a double?
Write a program that prompts the user to enter some number of pennies (1-cent coins), nickels (5-cent coins), dimes (10-cent coins), quarters (25-cent coins), half dollars (50-cent coins), and one-dollar coins (100-cent coins). Query the user separately for the number of each size coin, e.g.,
Write a program that takes an operation followed by two operands and outputs the result. For example:+ 100 3.14* 4 5Read the operation into a string called operation and use an if-statement to figure out which operation the user wants, for example, if (operation=="+"). Read the operands into
What kinds of literals are there?
What is a literal?
Write a program that converts spelled-out numbers such as “zero” and “two” into digits, such as 0 and 2. When the user inputs a number, the program should print out the corresponding digit. Do it for the values 0, 1, 2, 3, and 4 and write out not a number I know if the user enters something
Write a program to test an integer value to determine if it is odd or even. As always, make sure your output is clear and complete. In other words, don’t just output yes or no. Your output should stand alone, like The value 4 is an even number. Hint: See the remainder (modulo) operator in §3.4.
How would you writecout << "Hello, ";cout << fi rst_name;cout << "!\n";as a single line of code?
What terminates input into an integer?
Write a program that prompts the user to enter three integer values, and then outputs the values in numerical sequence separated by commas. So, if the user enters the values 10 4 6, the output should be 4, 6, 10. If two values are the same, they should just be ordered together. So, the input 4 5 4
What terminates input into a string?
What is \n called and what purpose does it serve?
Write a program that prompts the user to enter two integer values. Store these values in int variables named val1 and val2. Write your program to determine the smaller, larger, sum, difference, product, and ratio of these values and report them to the user.
If you want the user to input an integer value into your program for a variable named number, what are two lines of code you could write to ask the user to do it and to input the value into your program?
Write a program that doesn’t do anything, but declares a number of variables with legal and illegal names (such as int double = 0;), so that you can see how the compiler reacts.
Which operator do you use to read into a variable?
Write a program in C++ that converts from miles to kilometers. Your program should have a reasonable prompt for the user to enter a number of miles. Hint: There are 1.609 kilometers to the mile.
If you haven’t done so already, do the Try this exercises from this chapter.
What is meant by the term prompt?
Please don’t underestimate the importance of the notion of type safety. Types are at the center of most notions of correct programs, and some of the most effective techniques for constructing programs rely on the design and use of types — as you’ll see in Chapters 6 and 9, Parts II, III, and
If you understand everything in the textbook, why is it necessary to practice?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and
What is an IDE and what does it do for you?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may have to reread
What is the difference between a source file and an object file?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You
What does the linker do for your program?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may have to reread whole
What does a .h suffix at the end of a file name signify in C++?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may
What is the purpose of the #include directive?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may have to reread
Write a definition for each of the terms from “Terms.” First try to see if you can do it without looking at the chapter (not likely), then look through the chapter to find definitions. You might find the difference between your first attempt and the book’s version interesting. You might
What is the purpose of the compiler?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may have to reread whole
Find a good cookbook. Read the instructions for baking blueberry muffins (if you are in a country where “blueberry muffins” is a strange, exotic dish, use a more familiar dish instead). Please note that with a bit of help and instruction, most of the people in the world can bake delicious
In the “Hello, World!” program, what is the purpose of the line return 0;?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and
Write a description of how to get from the front door of your dorm room, apartment, house, whatever, to the door of your classroom (assuming you are attending some school; if you are not, pick another target). Have a friend try to follow the instructions and annotate them with improvements as he or
Name a function that must appear in every C++ program.The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may have to
Expanding on what you have learned, write a program that lists the instructions for a computer to find the upstairs bathroom, discussed in §2.1. Can you think of any more steps that a person would assume, but that a computer would not? Add them to your list. This is a good start in “thinking
Name the four parts of a function.The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may have to reread whole
What’s so important about the “Hello, World!” program? Its purpose is to get us acquainted with the basic tools of programming. We tend to do an extremely simple example, such as “Hello, World!,” whenever we approach a new tool. That way, we separate our learning into two parts: first we
Change the program to output the two linesHello, programming!Here we go!We list drills separately from exercises; always complete the chapter drill before attempting an exercise. Doing so will save you time.
What is the purpose of the “Hello, World!” program?The basic idea of these review questions is to give you a chance to see if you have noticed and understood the key points of the chapter. You may have to refer back to the text to answer a question; that’s normal and expected. You may have to
What are some uses of software that make your life more difficult?
What are some uses of software that make your life easier?
Why can software development be difficult? List some reasons.
What are the stages of software development?
What does a software developer look like?
How much memory does your computer have? Main memory? Disk?
Showing 500 - 600
of 628
1
2
3
4
5
6
7
Step by Step Answers