Você está na página 1de 5

Unit 1 Assignment A

Why do you need to translate a program written in a high-level language into machine
language? (2 points)
You need a compiler. The code needs to be compiled to machine code, which is binary.
Chapter 1 : Exercise 13 - What is linking? (2 points)
A compilation of functions, objects, classes, etc that get compiled with your program.
Links help to modularize your code and keeps things simpler.
Chapter 1: Exercise 15 - Provide the pseudocode that would be associated with your
solution. Write a short paragraph describing how you came up with your answer (2
points)

=START CODE=
.75 * .20 = .15
.95 * .35 = .3325
.85 * .15 = .1275
.65 * .30 = .195
.15 + .3325 + .1275 + .195 = .805, rounded to .80
Score is 80%
=END CODE=
COMMENTS: Im really confused on this exercise. What exactly are you trying to get
us to do? Does it need to be coded into a C++ program, or is this just a though exercise
to get us to see if we understand how to think this through before it goes into a program.
Please let me know if Im doing this wrong.
Chapter 2: Exercise 4 - What is a keyword and what is a user-defined identifier? (2
points)
A user-defined identifier would be a variable, constant, string, function, or label that the
programmer has created to store data or results from the program. A keyword is a
reserved word that can only be used in its defined state, like double, int, const, or float,
which are keywords used for different numbers.

Chapter 2: Exercise 22 - Resolve the syntax errors. Please rewrite the program entirely
with your corrections included. What do you predict will be the output of the corrected
code? Write each program in Visual C++ or your choice for an IDE (this is to be
decided by your instructor) and compile and run them. What was the output? If different
than your predictions, can you explain why? (4 points)

=START CODE=
#include <iostream>
#include <string>
using namespace std;
const long TOP_NUM = 753409;
const PAY_RATE = 18.35;
int main()
{
int testScore, projectScore, first, topNum1, newTemp;
double temp, hoursWorked, payCheck;
hoursWorked = 40;
testScore = 88;
projectScore = 22;
cout << "Test Score: " << testScore << endl;
cout << "Project Score: " << projectScore << endl;
temp = 82;
newTemp = testScore + 2 * projectScore;
first = 2 * TOP_NUM;

topNum1 = TOP_NUM - 919;


cout << "First: " << first << endl;
cout << "Top Number: " << topNum1 << endl;
payCheck = hoursWorked * PAY_RATE;
cout << "Wages = " << payCheck << endl;
return 0;
}
=END CODE=
COMMENTS: Im not sure here, but it appears it may be to generate test score and pay
rate, maybe together. It doesnt spit out anything useful here, even with the added hours
worked. I dunno. Pray tell.
Submit your assignment using the link above (due on Sunday of this unit; 12 points).

Unit 1 Assignment B
Programming Assignment - Programming Exercises #2 (Chapter 2)
Write a C++ program that produces the output shown (page 114). Submit the source
code only (no screen shots required) (15 points)

=START CODE=
#include <iostream>
#include <string>
using namespace std;
main()
{
cout << "CCCCCCCCC
++
++" << endl;
cout << "CC
++
++" << endl;
cout << "CC
++++++++++++++ ++++++++++++++" << endl;
cout << "CC
++++++++++++++ ++++++++++++++" << endl;
cout << "CC
++
++" << endl;
cout << "CCCCCCCCC
++
++" << endl;
}
=END CODE=
Programming Assignment (not in book)
Write and execute a C++ program that prompts you for your name, age and favorite
color and then prints them out after you have entered them in. Turn in the C++ code and
a screen snap of the results when you run the program. To get a screen shot on a PC, use
PrtSc (you may have to use the "fn" key on a laptop) and then open Microsoft Word and
paste the picture then submit the word document too. Other types of computers should
have similar capabilities. (15 points)

=START CODE=
#include <iostream>
#include <string>
using namespace std;
main ()
{
string txtStr;
cout << "What is your name?" << endl;
cin >> txtStr;
cout << "Hello " << txtStr << endl;
cout << "What is your age?" << endl;
cin >> txtStr;
cout << "Your age is " << txtStr << endl;
cout << "What is your favorite color?" << endl;
cin >> txtStr;
cout << "Your favorite color is " << txtStr << endl;
}
=END CODE=

Submit your assignment using the link above (due on Sunday of this unit; 30 points total).

Você também pode gostar