Solutions Manual for Introduction to C++ Programming
and Data Structures 5th edition by Daniel Liang
Solutions Manual for Introduction to C++ Programming
and Data Structures 5th edition by Daniel Liang
,Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang
Liang C++ 5E Revel Assigned Programming Quiz and Programming Project Solution
Note: For every question you entered, test it using the solution.
Chapter 1
Programming Quiz 1.6: Question 1: (00000-10501)
Write a statement that prints Hello World to the screen.
cout << "Hello World";
Programming Quiz 1.6: Question 2: (00000-10502)
Write a complete program that prints Hello World to the screen.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World";
return 0;
}
Programming Quiz 1.6: Question 3: (00000-10503)
Suppose your name was Alan Turing. Write a statement that would print your last name, followed by a
comma, followed by your first name.
Do not print anything else (that includes blanks).
cout << "Turing,Alan";
Chapter 1: Programming Project 1: (345021-00007)
(Display three messages)
Write a program that displays
Welcome to C++
Welcome to Computer Science
Programming is fun
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++" << endl;
cout << "Welcome to Computer Science" << endl;
Solutions Manual for Introduction
cout << "Programming to C++ Programming and Data
is fun" << endl;
Structures 5th edition by Daniel Liang
return 0;
,Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang
}
Chapter 1: Programming Project 2: (345021-00008)
(Compute expressions)
Write a program that displays the result of
(9.5 x 4.5 - 2.5 x 3) / (45.5 - 3.5)
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream>
using namespace std;
int main()
{
cout << (9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5) << endl;
return 0;
}
Chapter 1: Programming Project 3: (345021-00009)
(Population projection)
The U.S. Census Bureau projects population based on the following assumptions:
One birth every 7 seconds.
One death every 13 seconds.
One new immigrant every 45 seconds
Write a program that displays the population for each of the next five years. Assume the current
population is 312,032,486 and one year has 365 days.
Hint: In C++, if two integers perform division, the result is the quotient. The fractional part is truncated.
For example, is 1 (not 1.25) and is 2 (not 2.5). To get an accuate result with the fractional
part, one of the values involved in the division must be a number with a decimal point. For example, 5.0
/ 4 is 1.25 and .0 is 2.5.
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream>
using namespace std;
int main()
{
cout << 312032486 + 365 * 24 * 60 * .0 - 365 * 24 * 60 * 60 / 13.0 +
365 * 24 * 60 * .0 << endl;
cout << 312032486 + 2 * 365 * 24 * 60 * .0 - 2 * 365 * 24 * 60 * 60
/ 13.0 + 2 * 365 * 24 * 60 * .0 << endl;
cout << 312032486 + 3 * 365 * 24 * 60 * .0 - 3 * 365 * 24 * 60 * 60
/ 13.0 + 3 * 365 * 24 * 60 * .0 << endl;
cout << 312032486
Solutions + 4Introduction
Manual for * 365 * 24 * to
60 * 60 Programming
C++ / 7.0 - 4 * 365
and* Data
24 * 60 * 60
/ 13.0 + 4 * 365 * 24 * 60 * .0 << endl;
Structures 5th edition by Daniel Liang
, Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang
cout << 312032486 + 5 * 365 * 24 * 60 * .0 - 5 * 365 * 24 * 60 * 60
/ 13.0 + 5 * 365 * 24 * 60 * .0 << endl;
return 0;
}
Chapter 1: Programming Project 4: (345021-00153)
(Simple computation)
The formula for computing the discriminant of a quadratic equation ax^2 + bx + c = 0 is b^2 –
4ac. Write a program that computes the discriminant for the equation 3x^2 + 4x + 5 = 0.
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream> // Exercise01_01Extra
using namespace std;
int main()
{
cout << 4 * 4 - 4 * 3 * 5 << endl;
return 0;
}
Chapter 1: Programming Project 5: (345021-00154)
(Physics: acceleration)
Average acceleration is defined as the change of velocity divided by the time taken to make the
change, as shown in the following formula:
a = (v1 - v0) / t
Here, v0 is the starting velocity in meters/second, v1 is the ending velocity in meters/second, and t is
the time span in seconds. Assume v0 is 5.6, v1 is 10.5, and t is 0.5, and write the code to display the
average acceleration.
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream> // Exercise01_02Extra
using namespace std;
int main()
{
cout << (10.5 - 5.6) / 0.5 << endl;
return 0;
}
Chapter 2
Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang
and Data Structures 5th edition by Daniel Liang
Solutions Manual for Introduction to C++ Programming
and Data Structures 5th edition by Daniel Liang
,Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang
Liang C++ 5E Revel Assigned Programming Quiz and Programming Project Solution
Note: For every question you entered, test it using the solution.
Chapter 1
Programming Quiz 1.6: Question 1: (00000-10501)
Write a statement that prints Hello World to the screen.
cout << "Hello World";
Programming Quiz 1.6: Question 2: (00000-10502)
Write a complete program that prints Hello World to the screen.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World";
return 0;
}
Programming Quiz 1.6: Question 3: (00000-10503)
Suppose your name was Alan Turing. Write a statement that would print your last name, followed by a
comma, followed by your first name.
Do not print anything else (that includes blanks).
cout << "Turing,Alan";
Chapter 1: Programming Project 1: (345021-00007)
(Display three messages)
Write a program that displays
Welcome to C++
Welcome to Computer Science
Programming is fun
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++" << endl;
cout << "Welcome to Computer Science" << endl;
Solutions Manual for Introduction
cout << "Programming to C++ Programming and Data
is fun" << endl;
Structures 5th edition by Daniel Liang
return 0;
,Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang
}
Chapter 1: Programming Project 2: (345021-00008)
(Compute expressions)
Write a program that displays the result of
(9.5 x 4.5 - 2.5 x 3) / (45.5 - 3.5)
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream>
using namespace std;
int main()
{
cout << (9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5) << endl;
return 0;
}
Chapter 1: Programming Project 3: (345021-00009)
(Population projection)
The U.S. Census Bureau projects population based on the following assumptions:
One birth every 7 seconds.
One death every 13 seconds.
One new immigrant every 45 seconds
Write a program that displays the population for each of the next five years. Assume the current
population is 312,032,486 and one year has 365 days.
Hint: In C++, if two integers perform division, the result is the quotient. The fractional part is truncated.
For example, is 1 (not 1.25) and is 2 (not 2.5). To get an accuate result with the fractional
part, one of the values involved in the division must be a number with a decimal point. For example, 5.0
/ 4 is 1.25 and .0 is 2.5.
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream>
using namespace std;
int main()
{
cout << 312032486 + 365 * 24 * 60 * .0 - 365 * 24 * 60 * 60 / 13.0 +
365 * 24 * 60 * .0 << endl;
cout << 312032486 + 2 * 365 * 24 * 60 * .0 - 2 * 365 * 24 * 60 * 60
/ 13.0 + 2 * 365 * 24 * 60 * .0 << endl;
cout << 312032486 + 3 * 365 * 24 * 60 * .0 - 3 * 365 * 24 * 60 * 60
/ 13.0 + 3 * 365 * 24 * 60 * .0 << endl;
cout << 312032486
Solutions + 4Introduction
Manual for * 365 * 24 * to
60 * 60 Programming
C++ / 7.0 - 4 * 365
and* Data
24 * 60 * 60
/ 13.0 + 4 * 365 * 24 * 60 * .0 << endl;
Structures 5th edition by Daniel Liang
, Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang
cout << 312032486 + 5 * 365 * 24 * 60 * .0 - 5 * 365 * 24 * 60 * 60
/ 13.0 + 5 * 365 * 24 * 60 * .0 << endl;
return 0;
}
Chapter 1: Programming Project 4: (345021-00153)
(Simple computation)
The formula for computing the discriminant of a quadratic equation ax^2 + bx + c = 0 is b^2 –
4ac. Write a program that computes the discriminant for the equation 3x^2 + 4x + 5 = 0.
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream> // Exercise01_01Extra
using namespace std;
int main()
{
cout << 4 * 4 - 4 * 3 * 5 << endl;
return 0;
}
Chapter 1: Programming Project 5: (345021-00154)
(Physics: acceleration)
Average acceleration is defined as the change of velocity divided by the time taken to make the
change, as shown in the following formula:
a = (v1 - v0) / t
Here, v0 is the starting velocity in meters/second, v1 is the ending velocity in meters/second, and t is
the time span in seconds. Assume v0 is 5.6, v1 is 10.5, and t is 0.5, and write the code to display the
average acceleration.
For a hint on this program, please see https://liangcpp.pearsoncmg.com/cpprevel2e.html. If you get a
logic or runtime error, please refer to https://liangcpp.pearsoncmg.com/faq.html.
#include <iostream> // Exercise01_02Extra
using namespace std;
int main()
{
cout << (10.5 - 5.6) / 0.5 << endl;
return 0;
}
Chapter 2
Solutions Manual for Introduction to C++ Programming and Data
Structures 5th edition by Daniel Liang