COMP122
Week 1 Homework
Part 1: Complete the following problems.
1. What is machine code? Why is it preferable to write programs in a high level language such as C++?
2. What does a compiler do? What kinds of errors are reported by a compiler?
3. What does the linker do?
4. What is an algorithm?
5. Bob enters a pizza shop and notices there are three different sizes of pizzas available. Sizes are given as the diameter of the pizza in inches. The cost of a pizza is based on the size. Bob would like to know which size of pizza has the lowest cost per square inch.
a. Identify the inputs and outputs for this problem.
b. Identify the processing needed to convert the inputs to the outputs.
c. Design an algorithm
…show more content…
b. Declare and initialize an int variable temp to 10 and a char variable ch to 'A'. c. Add 5 to the int variable x which already exists. d. Declare and initialize a double variable payRate to 12.50. e. Copy the value from an existing int variable firstNum into an existing int variable tempNum. f. Swap the contents of existing int variables x and y. (Declare any new variables you need.) g. Output the contents of existing double variables x and y, and also output the value of the expression x + 12 / y - 8. h. Copy the value of an existing double variable z into an existing int variable x.
5. Given the following variable declarations:
int x = 2, y = 5, z = 6;
What is the output from each of the following statements?
a. cout << "x = " << x << ", y = " << y << ", z = " << z << endl; b. cout << "x + y = " << x + y << endl; c. cout << "Sum of " << x << " and " << z << " is " << x + z << endl; d. cout << "z / x = " << z / x << endl; e. cout << "2 times " << x << " = " << 2 * x << endl;
6. Given the following variable declarations:
int a = 5, b = 6, c;
What is the value of a, b, and c after each of the following statements executes? Assume that the statements execute in the sequence given.
a. a = b++ + 3; b. c = 2 * a + ++b; c. b = 2 * ++c -
First let us take a look at computer programming. This element takes on different program designs created by engineers and uses one of several different programming languages to write executable code that computers can read. Programming is the source for
A. -8 + x [(let x be the variable number, therefore sum of variable (x) and (-8) would be x-8 or -8 + x)]
This project is designed to make the FPGA as a Calculator that receives two four bit binary numbers and do four different operations on those two numbers. The four operations are addition, subtraction, division, and XOR (bit wise operation). The project is designed with top model and sub modules. Moreover, when the user enters the two inputs in binary the result will display in decimal except for the last operation which is the bit wise (XOR) that should be displayed in binary. The only challenge part that I wasn’t able to fix is I have very long code because I saved the result from add, subtract, and multiplication in a register and had to do check from 0-225 cases and that’s how I can display the binary numbers on the FPGA board.
if (min != i)// if min was redefined, swaps the values of the i and min
Loop While ans <> "Y" And ans <> "y" And ans <> "N" And ans <> "n"
6. (TCO 3) Which pseudocode produces the same result as the following? if customerAge > 65 OR customerAge = 65 then
For each of the two programming problems, create a program using Visual C++.Net. Make sure to capture a sample of your program's output. The best way to do this is to click on the console window you want to capture and then press the Alt and PrintScreen keys at the same time. Then paste your captured screen image into a Word document. For each of the two programs, put the screen capture followed by a copy of your source code into your Word document.
When you are multiplying fractions you multiply the numbers on top as well as the numbers on the bottom. For example:
Overflow occurs when the two numbers of similar signs are added together and a result with an opposite sign is produced.
We are using two FOR Loop to traverse the input and create a 2 dimensional array for printing the output.
1. Consider the right most digit of the message to be in an "Odd" position, and assign odd/even
1. If a coffee company purchases paper cups at a cost of x cents for a package of ten and lids at a cost of y cents per dozen, which of the following represents its material cost, in cents, of c cups of coffee?
Each programming language uses a piece of software, called a compiler or an interpreter, to translate your program code into machine language. Machine language is also called binary language, and is represented as a series of 0s and 1s. The compiler or interpreter that translates your code tells you if any programming language component has been used incorrectly. Syntax errors are relatively easy to locate and correct because the compiler or interpreter you use highlights every syntax error. If you write a computer program using a language such as C++ but spell one of its words incorrectly or reverse the proper order of two words, the software lets you know that it found a mistake by displaying an error message as soon as you try to translate the program.
main(){ float fahr, cels; int lower, upper, step; lower = 0; //lower limit of the table upper = 300; //upper limit step = 20; //step size fahr = lower; printf("Fahrenheit - Celsius table\n"); while (fahr , fahr, cels); fahr = fahr + step; } }
The method reads the key matrix. The user will enter in the first number and press “enter” and do this