FrankSJSU
Sunday, April 8, 2018
Wednesday, June 25, 2014
I don't understand the BITWISE Operators
Bitwise operators, shift left, shift right, bitwise OR, bitwise AND, etc, are typically used in association with the hardware. Wikipedia has a very detail description of their functionalities. I won't repeat it here. Instead, I'll try to explain how it is used with an example.
Suppose we want to independently control three lights: red, green, yellow. Computer can implement it with a few methods:
Suppose we want to independently control three lights: red, green, yellow. Computer can implement it with a few methods:
- 6 distinct addresses and ignore data: Ron, Roff, Gon, Goff, Yon, Yoff
- 3 distinct addresses and use 1 to turn on, 0 to turn off. Ex. Red(1) turns red on, Green(0) turns green off.
- 1 address and use 3 bits data: each bit control different light. If you do not know bits, please check wiki's binary number. Ex. Light(101) turns R on, G off, Y on.
The single address case (the last one) is where we need to use bitwise logic. Try this question:
- How do you turn on Green and keep the other lights unchanged?
- How do you turn off Green and keep the other lights unchanged?
Shift operations are usually used with math. The number is divided by 2 if you shift right and multiplied by 2 if you shift left. Of course, there are other usage too.
Tuesday, June 24, 2014
Learning C++ in N Questions
Hello
H01 Can you print out "hello world"?H02 Can you ask user a number and then print out "hello 1", "hello 2", ..., "hello n"?
H03 Can you stop the program on each loop and examine the number n?
Statistics
M10 Can you ask user for n numbers and calculate the average?
M11 Can you ask user for n numbers and calculate average, max, min?
M12 Can you read in a file of numbers, count how many numbers, and calculate average, max, min?
M11 Can you ask user for n numbers and calculate average, max, min?
M12 Can you read in a file of numbers, count how many numbers, and calculate average, max, min?
M13 Can you also count how many numbers are above the average?
M21 Can you print these numbers from small to large?
M23 Can you print the "median" of these numbers?
Customer
You have a customer file, each line has a customer name and the balance.
C30 Can you create a customer object and calculate average balance?
C31 Can you print the customers from small balance to large balance?
C31 Can you print the customers from small balance to large balance?
C32 Can you print the customers alphabetically?
C33 Can you print the customer with median balance?
C41 Can you find a specific customer and print his balance?
C42 Can you change a customer's balance?
C43 Can you add another customer to the customer file?
C44 Can you delete a customer and recalculate the statistics?
Q&A
Saturday, June 21, 2014
What shall I learn in IDE?
Assumption:
You have started on the C/C++ program and already run a few tutorials from cplusplus.com, as discussed in Like-To-Learn-C++.Objective:
Learn a few essential things with the IDE.- create and run a C++ program. If you did some tutorial, it is obviously you can do that.
- breakpoint and single step. It is essential that a programmer can debug a program. Many students do their debugging by printing to console. It will work except that it is not effective at all. Write a simple looping program (e.g. compute average) and practice single step will go a long way.
- examine variables. While you're step through your code, figure out how to see the values of your variables (both global and local). The combination of breakpoints and variable examination are the two fundamental debugging skills that every programmer shall have.
Those three things are the essentials. Other IDE features, e.g. renaming a variable/procedure, are useful, but you can pick it up later. No hurry.
Wednesday, June 18, 2014
I like to learn C++
Assumption:
I want to learn C++, but I do not know anything about it.
Question:
Where do I start?The most effective way I know is to learn by doing. Here are my recommended steps.
- download a software that allows you to practice writeing C++ programs.
There are two popular free software (it is called IDE -- Integrated Development Environment). One is Microsoft Visual C++ Express. It comes with a compiler already. If you're running Windows, this is the easiest way.
The other popular IDE is Eclipse. Eclipse was originally designed for Java. However, it is well adapted to C++. When you search for download, try "eclipse CDT" (C Development Tooling). Many good installation guides are readily available, one example here.
- get yourself comfortable (well, a little bit) with the IDE
Run the built-in "hello world" program. Both microsoft and Eclipse come with a good tutorial. No need to finish them all though.
- go to cplusplus.com and follow the tutorials there
- follow a textbook or university course material
My C++ class materials (in fact, two of them) are on line. CMPE50 is for students who knows some C program. CMPE46 is for students who does not have C exposure.
There are two popular free software (it is called IDE -- Integrated Development Environment). One is Microsoft Visual C++ Express. It comes with a compiler already. If you're running Windows, this is the easiest way.
The other popular IDE is Eclipse. Eclipse was originally designed for Java. However, it is well adapted to C++. When you search for download, try "eclipse CDT" (C Development Tooling). Many good installation guides are readily available, one example here.
Run the built-in "hello world" program. Both microsoft and Eclipse come with a good tutorial. No need to finish them all though.
My C++ class materials (in fact, two of them) are on line. CMPE50 is for students who knows some C program. CMPE46 is for students who does not have C exposure.
Subscribe to:
Posts (Atom)