Hey again guys,
For those who missed the IRC class, I'll go over the quick lesson we were taught.
when do anything with an &&
if(a>3 && b>5)
OR
a>3 && printf("hello")
The part after '&&' will only be completed if the first part is true. Otherwise it skips the second part completely, aka lazy evaluation.
Monday, May 31, 2010
Saturday, May 22, 2010
Compiling Code for Platforms
In class we have learned how to only compile certain code when programming for multi-platforms.
Remember anything using the # sign talks directly with the compiler.
I will go over this just for a quick over view.
Remember anything using the # sign talks directly with the compiler.
In order to define the platforms, use the following format,
# DEFINE Linux 10
# DEFINE Windows 111
# DEFINE Mac 121
# DEFINE Platform Linux
After this is done, use the format
# if Platform=Linux /* Or any of the others */
/* do code */
# endif
/* Do for rest of platforms*/
Thursday, May 13, 2010
Answer and Explanation to Operand Example
Hey there fellow OOP344 students. Today's pop quiz thing went by pretty quick so I figured I'd show you guys the solution and explain it.
for(i=0;10>i; i++)
***ANSWER***
int main()
{
int i;
int n=0;
int j[10]={1,0,3,4,0,7,8,2,0,1};
{
n+=!j[i]; /*LINE OF CODE WANTED */
}
}
So in order to calculate the numbers of 0's within j's array [within one line], we must use the method taught today.
Firstly, remember 0 = FALSE, and 1 or greater than 1 = TRUE.
NOT (a number greater than 0) Returns FALSE; Aka NOT TRUE = FALSE.
so NOT (0) Returns TRUE; Aka NOT FALSE = TRUE.
So if the number in the array j[i] = 0, the expression !j[i] will become !0 Returns TRUE.
TRUE = 1, as we all should know.
So in conclusion, n+=1; adds one when j[i] = 0, adding all 0's.
If there is any confusion with the above, don't hesitate to ask me to try and clarify a bit more.
OOP344 at Seneca
Just started another semester at Seneca College. I'm taking a course called OOP344 which is pretty much advanced C++. Over the course of this semester I will be updating this blog on problems, solutions, and questions with regards to our text editor assignment we will be doing in groups.
Subscribe to:
Posts (Atom)