1. Both main memory and secondary storage are types of memory. Describe the difference
between the two.
2. What is the difference between system software and application software?
3. Why must programs written in a high-level language be translated into machine
language before they can be run?
4. In C++, to display data on your monitor you use the << operator. What do you call this
operator?
5. What is wrong with this program and how you fix it so it compiles?
int main()
}
// A crazy mixed up program
return 0;
#include <iostream>
cout << "In 1942 Columbus sailed the ocean blue.";
{
using namespace std;
6. A program has the following variable definitions.
long miles;
int feet;
float inches;
Write one cin statement that reads a value into each of these variables.
7. Write C++ statements using combined assignment operators to perform the following:
a) Add 6 to x
b) subtract 4 from amount
c) Multiply y by 4
d) divide total by 27
e) store in x the remainder of x divided by 7
8. Complete the following table by writing the value of each expression in the Value column
EXPRESSION VALUE
----------- -----
28/4 - 2
6 + 12 * 2 -8
4 + 8 * 2
6 + 17 % 3 - 2
2 + 22 * (9 - 7)
9. The following program ues an if/else if statement to assign a letter grade
(A,B,C,D, or F) to a numeric test score. THE PROGRAM HAS ERRORS. Find as
many as you can.
#include <iostream>
using namespace std;
int main() {
int testscore;
cout << "Enter your test score and I will tell you \n";
cout << "the letter grade you earned: ";
cin >> testscore;
if (testscore < 60)
cout << "your grade is F.\n";
else if (testscore < 70)
cout << "your grade is D.\n";
else if (testscore < 80)
cout << "your grade is C.\n";
else if (testscore < 90)
cout << "your grade is B.\n";
else
cout << "THAT IS NOT A VALID SCORE.\n");
else if (testscore <= 100)
cout << your grade is A.\n");
return 0;
}
10. Write a program that asks the user to enter two numbers. The program should use the
conditional operator to determine which number is the smaller and which is the larger.
11. Write a program that reports the contents of a compressed-gas cylinder based
on the first letter of the cylinder's color. The program input is a character
representing the observed color of the cylinder: 'Y' or 'y' for yellow, 'O'
or 'o' for orange, and so on. Cylinder colors and associated contents are as
follows:
Orange ammonia
Brown carbon monoxide
Yellow hydrogen
Green oxygen
Your program should respond to input of a letter other than the first letters
of the given colors with the message, "contents unknown."
12. Write a program that uses a "for" statement to calculate the average of
several integers. Assume that the last value read is the sentinel value
99999. For example, 10 8 7 13 9 9999 indicates that the program should
calculate the average of all the values preceding 9999
13. Assume "value" is an integer variable. If the user enters 3.14 in response to the following
programming statement, what will be stored in value?
int value;
cin >> value;
a) 3.14
b) 3
c) 0
14. You studied Type Casting in Chapter 3. Type casting allows you to perform manual data type
conversion.
Assume the following definitions:
int a = 5, b = 12;
double x = 3.4, z = 9.1;
What are the values of the following expressions?
a) b/a
b) x * a
c) static_cast<double>(b/a)
d) static_cast<double>(b) / a
e) b / static_cast<int>x;
15. cout object provides a way to format the data that is displayed on the screen. To format data,
you include the header file <iomanip>. To set the field width, you use the stream manipulator setw.
See Chapter 3. For example, if you like to display the number 15 in a field of width 5 spaces, you
would write
int number = 15;
cout << setw(5) << number;
This will display the number in a field 5 spaces wide, right-justified.
Write cout statement with stream manipulators that perform the following:
a) Display the number 34.789 in a field of 9 spaces with 2 decimal places of precision
b) Display the number 67 left justified in a field of 7 spaces.
16. Indicate whether the following statements about relational expressions are correct or incorrect.
a) x <= y is the same as y > x
b) x != y is the same as y >= x
c) x >= y is the same as y <= x
17. Rewrite the following code using a do-while statement with no decisions in the loop body:
sum = 0;
for (odd = 1; odd < n; odd = odd + 2)
sum = sum + odd;
18. What three things do you need to do to use a function in your program? Explain each one of them
giving examples.
between the two.
2. What is the difference between system software and application software?
3. Why must programs written in a high-level language be translated into machine
language before they can be run?
4. In C++, to display data on your monitor you use the << operator. What do you call this
operator?
5. What is wrong with this program and how you fix it so it compiles?
int main()
}
// A crazy mixed up program
return 0;
#include <iostream>
cout << "In 1942 Columbus sailed the ocean blue.";
{
using namespace std;
6. A program has the following variable definitions.
long miles;
int feet;
float inches;
Write one cin statement that reads a value into each of these variables.
7. Write C++ statements using combined assignment operators to perform the following:
a) Add 6 to x
b) subtract 4 from amount
c) Multiply y by 4
d) divide total by 27
e) store in x the remainder of x divided by 7
8. Complete the following table by writing the value of each expression in the Value column
EXPRESSION VALUE
----------- -----
28/4 - 2
6 + 12 * 2 -8
4 + 8 * 2
6 + 17 % 3 - 2
2 + 22 * (9 - 7)
9. The following program ues an if/else if statement to assign a letter grade
(A,B,C,D, or F) to a numeric test score. THE PROGRAM HAS ERRORS. Find as
many as you can.
#include <iostream>
using namespace std;
int main() {
int testscore;
cout << "Enter your test score and I will tell you \n";
cout << "the letter grade you earned: ";
cin >> testscore;
if (testscore < 60)
cout << "your grade is F.\n";
else if (testscore < 70)
cout << "your grade is D.\n";
else if (testscore < 80)
cout << "your grade is C.\n";
else if (testscore < 90)
cout << "your grade is B.\n";
else
cout << "THAT IS NOT A VALID SCORE.\n");
else if (testscore <= 100)
cout << your grade is A.\n");
return 0;
}
10. Write a program that asks the user to enter two numbers. The program should use the
conditional operator to determine which number is the smaller and which is the larger.
11. Write a program that reports the contents of a compressed-gas cylinder based
on the first letter of the cylinder's color. The program input is a character
representing the observed color of the cylinder: 'Y' or 'y' for yellow, 'O'
or 'o' for orange, and so on. Cylinder colors and associated contents are as
follows:
Orange ammonia
Brown carbon monoxide
Yellow hydrogen
Green oxygen
Your program should respond to input of a letter other than the first letters
of the given colors with the message, "contents unknown."
12. Write a program that uses a "for" statement to calculate the average of
several integers. Assume that the last value read is the sentinel value
99999. For example, 10 8 7 13 9 9999 indicates that the program should
calculate the average of all the values preceding 9999
13. Assume "value" is an integer variable. If the user enters 3.14 in response to the following
programming statement, what will be stored in value?
int value;
cin >> value;
a) 3.14
b) 3
c) 0
14. You studied Type Casting in Chapter 3. Type casting allows you to perform manual data type
conversion.
Assume the following definitions:
int a = 5, b = 12;
double x = 3.4, z = 9.1;
What are the values of the following expressions?
a) b/a
b) x * a
c) static_cast<double>(b/a)
d) static_cast<double>(b) / a
e) b / static_cast<int>x;
15. cout object provides a way to format the data that is displayed on the screen. To format data,
you include the header file <iomanip>. To set the field width, you use the stream manipulator setw.
See Chapter 3. For example, if you like to display the number 15 in a field of width 5 spaces, you
would write
int number = 15;
cout << setw(5) << number;
This will display the number in a field 5 spaces wide, right-justified.
Write cout statement with stream manipulators that perform the following:
a) Display the number 34.789 in a field of 9 spaces with 2 decimal places of precision
b) Display the number 67 left justified in a field of 7 spaces.
16. Indicate whether the following statements about relational expressions are correct or incorrect.
a) x <= y is the same as y > x
b) x != y is the same as y >= x
c) x >= y is the same as y <= x
17. Rewrite the following code using a do-while statement with no decisions in the loop body:
sum = 0;
for (odd = 1; odd < n; odd = odd + 2)
sum = sum + odd;
18. What three things do you need to do to use a function in your program? Explain each one of them
giving examples.
相关推荐
代写C程序 C++ Linux Unix 数据结构 操作系统
【标题】"C++编写的高频交易源码程序"揭示了使用C++这一高效编程语言构建的高频交易系统的实现细节。高频交易(High-Frequency Trading,HFT)是一种利用先进的算法和技术,在极短时间内执行大量交易的策略。这种...
C++版本的源代码可能包括了类定义、函数实现、主程序等部分,利用C++的结构化特性,将算法的各个组件封装在不同的类或函数中,通过控制流程实现搜索过程。而MATLAB版本的代码则会使用MATLAB的向量化操作和内建函数,...
学、英语、C++语言程序设计)的成绩和平均成绩构成。实现功能包括: (1) 教师功能: 添加学生的记录:添加新生的学号、姓名、班级、三门课(高等数学、英语、 C++语言程序设计)的成绩,并计算该生平均成绩。将学生信息...
同时,系统应具备一定的错误处理能力,比如在用户输入错误信息时提供相应的提示,避免程序因异常而崩溃。 在实际应用中,这样的电影购票系统可以部署在电影院的自助购票机上,也可以作为在线服务平台供用户通过网络...
MFC 是微软提供的一种C++类库,用于简化Windows应用程序的开发,它将Windows API封装成易于使用的C++类,让开发者可以更加高效地构建用户界面和应用程序逻辑。 在压缩包中,有两个关键文件:"Bejeweled.sln" 和 ...
在本文中,我们将深入探讨如何使用VC++(Visual C++)进行模拟时钟软件的开发。模拟时钟源代码是编程领域中一个基础且有趣的项目,它可以锻炼开发者对时间管理、用户界面设计以及多线程处理的理解。让我们一起剖析这...
1)录入:录入促销信息,退出程序时要存储到文件中。录入格式内容自行设计。至 少包括:商品类型、商品名称、商品细节、原价、促销活动、促销时间、促销商家。 2)查询:根据商家、商品名称查询促销信息 (2)购物咨理 1...
(4)物品存盘:将当前程序中的物品信息存入文件中。 (5)编辑物品:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。 (6)删除物品:主要完成图书馆物品信息的删除。如果当前物品库为空,则提示"物品库为空!...
实验内容:设计一个程序,把中缀表达式转换成- -棵二叉树, 然后通过后根遍历计算表达式的值。 实验目的与要求:对于输入的一-个中缀表达式,判断表达式是否合法。如果合法,把中缀表达式转换成- -棵二叉树,然后通过...
博主还提供包括毕业设计、课程作业、期末大作业的代写代做以及学习资料、程序开发、技术解答、代码讲解、文档报告等专业服务,并且可以在文章末尾联系博主。 文章中详细展示了系统的运行效果,包括用户登录界面、...
博主也提供了相关的服务,如毕业设计、课程作业、期末大作业的代写代做,以及学习资料、程序开发、技术解答、代码讲解、文档报告等专业服务。在其服务的末尾,博主还留有联系方式,方便有需求者与其取得联系。 对于...
编程软件:DevC++ 数据存储:链表 内容描述: 1.本演示中,集合的元素限定为小写字母['a'..'z'],集合的大小n,集合输入的形式为一个以‘回车符’为结束标志的字符串,串中字符顺序不限,且允许出现重复字符或非法...
他注重代码规范、性能优化和代码重构,为学生和开发者提供全方位的技术支持和交流,提供包括但不限于毕业设计、课程作业、期末大作业的代写代做、学习资料、程序开发、技术解答、代码讲解和文档报告等专业服务。...
在技术层面,文章作者强调了自己在多个编程语言和框架上的深厚功底,包括但不限于Java、Python、C#、C、C++以及微信小程序、Php和Android等。作者不仅提供技术咨询和问题解答,还提供代写代做毕业设计、课程作业等...
5. 技术支持:提供毕业设计、课程作业、期末大作业的代写代做等服务。 四、问题解决与系统优化 1. 编码问题解决:系统在开发时采用GBK编码,在导入eclipse时需要将工作空间编码也设置为GBK,否则会出现乱码。若要...
C++Builder是一种高效的开发工具,它支持创建高效、性能良好的应用程序。将MATLAB的算法能力与C++Builder的系统级执行能力结合起来,可以开发出既拥有高级算法支持,又具备快速执行能力的应用程序。例如,在锅炉和...