In the table below, you'll see some decimal numbers in the left hand side. These are your targets. In the middle of the table, you see a row of black and red dots. These represent LED's. Red means binary 1. Black means binary 0. Go ahead and mash one of the dots. It changes state -- 0 becomes 1, 1 becomes 0. Notice that the rightmost number also changes. It is the decimal number corresponding to the binary number.
Your job is to set the binary bits so that the right column matches the left column, if possible, be prepared to explain your answers.
Target | Your guess |
---|---|
20 | |
43 | |
66 | |
99 | |
127 | |
128 |
Now try out binary representations using 16 bits.
Target | Your guess |
---|---|
128 | |
256 | |
511 | |
2000 | |
32767 |
Ask your lab instructor to verify that you've pushed all the right buttons.
Open a new C++ Source File in Lab03.cpp and type in the following outline of the main function:
// Lab 3 -- CSCI 201.0L? // Your Name // #include <iostream.h> int main() { return 0 ; }
Even though this program does absolutely nothing, go ahead and Build it, just to make sure you've created the program, project, and workspace correctly.
At the beginning of your program, add declarations for two integer variables i and j and two float variables y and z.
Now add statements to read user-provided values for these variables. Be sure to prompt before reading each value. Here's some example code for setting i.
cout << "Enter integer value for i" << endl ; cin >> i ;
Finally, write statements to print the eight expressions listed in the following table:
Expression Number | Expression |
---|---|
1 | Average of y and z |
2 | Average of i and j |
3 | The reminder when i is divided by j |
4 |
2 y + 4 j z |
5 |
2 3 -(y - z ) |
6 |
y + z ------- y - z |
7 |
i -------- i + 1 |
8 |
i --------- i + 1.0 |
9 |
i --- * j j |
cout << "Expression 1 is " << (y+z)/2 << endl ;
After you have thoroughly tested your code, ask your instructor to test it.
Write a program that computes the number of seconds, minutes and hours in a given number of seconds. The outline of the main function is given below. You need to fill in the missing expressions.
// Lab 3 -- CSCI 201.0L?
// Your Name
//
#include <iostream.h>
int main()
{
int totalSeconds, minutes, hours, seconds;
cout << "Enter the total number of seconds: " << flush;
cin >> totalSeconds;
// there are 3600 seconds in a hour
hours =
// there are 60 seconds in a minute
minutes =
// the remaining seconds
seconds =
cout << totalSeconds << " written as hours:minutes:seconds = "
<< hours << ":" << minutes << ":"
<< seconds << endl;
return 0;
}
After you have tested your code, ask your instructor to test it.