|
Registered User
Join Date: Dec 2004
Posts: 43
|
C++ test I made, need one to look over...
Alright, I am reading C++ for dummies, and I'm making some good sense out of it after some months trying to understand it. Now I want to test my self, so I am im the process of making a test... this is what I have so far...
C++ for Dummies Quiz
Chapter 1-6
1.Do you have to tell what variable it needs to use before it uses one?
Answer: No, if you don't assign C++ the type of variable before its use, it will automaticly be an int.
2.“int” is C++'s equivelent to...
Answer: An integer, a number that has no fractional part.
3.Name the C++'s operators and what they coincide with...
Answer: + for addition, - for subtraction, * for multiplication, / for division, and % for modulus.
4.What is modulus?
Answer: Modulus is like division, except it shows only the remainder of a division calculation. Ex: “11 % 3 = 2” as the remainder.
5.Does C++ calculate from right to left? Or from left to right? Any exceptions?
Answer: C++ calculations go from left to right. With the exception of PEMDAS (Perenthesis, Exponents, Multiplication, Division, Addition, Subtraction) which is something that C++ goes along with. But if a Division operator comes before a multiplication operator, or vice versa, it goes in that order. Same goes for Addition, and Subtraction.
6.What is precedence?
Answer: Precedence refers to the order in which operators are evaluated. Which also refers to PEMDAS.
7.What are the unary operators? And what do they mean/do?
Answer: Unary operators are +, -, ++, - -. The first two, - and +, are what they are. But the second two ++, and - -, are called autoincrements, which increase a value by one, or decrease a value by one. They are used extensively in “for” statements.
8.What is an expression?
Answer: An expression is a statement involving any sort of mathematical operation, that gives (returns) a value.
9.Explain the shown examples in detail...
// example 1
int n1, n2;
n1 = 5;
n2 = ++n1;
// example 2
int n1, n2;
n1 = 5;
n2 = n1++;
Answer: n1++ and ++n1 both add one to their variable. The first example shows n1 initialized as 5, then changed to 6 after n2 was initialized the same as n1 but with autoincrement, changing both values to 6. Example 2 shows n1 initialized to 5, then n2 initialized the same as n1, also incremented but with the ++ unary operators pointed to the right, changing n2 from 5 to 6, but leaving n1 to 5.
10.What is an assignment operator?
Answer: An assignment operator is an operator that changes the value of its left hand argument. Example: the equal sign in 1 + 2 = 3, the equal sign in the operator.
11.If the same variable appears on both sides of the assignment operator, could you then just skip rewriting it and use something that takes less space? If so, what could be changed?
Answer: Yes, if on both sides of the assignment operator are the same, exmple: “nVariable = nVariable + 2”, you could rewrite it like this... “nVariable += 2”, which makes a clone of itself and puts it on the right of the assignment operator, but adds two.
12.Where the + sign is in this example “nVariable += 2”, could you replace it with other operators?
Answer: Yes.
13.What are logical operators?
Answer: They are “And”, “If's” and “Or” statements.
14.Write down what you believe each character means...
== Answer: Equality; true if the left handed arg. Is the same as the right.
!= Answer: Inequality; opposite of equality.
>, < Answer: Greater then, less then; true if the left handed arguemnt is greater than or less than the right handed arg.
>=,<= Answer: Greater then or equal to, less then or equal to; true if either > or = = is true, OR either , or = = is true.
&& Answer: AND; true if both left and right args. are true.
|| Answer: ! NOT; true if its argument is false.
15.Can you combine logical operators? If so, give an example.
Answer: Yes, (n1 < n2) && (n2 < n3);
16.What kind of variable allows you to store logical values into? Example?
Answer: bool variables.
int n1 = 1;
int n2 = 2;
bool b;
b = (n1 = = n2);
17.What statement makes sure that bool variables output “true” and “false”?
Answer: cout.setf(cout.boolalpha);
18.If you truncate cout, from cout.setf, you will still get true or false outputs from bool statements.
Answer: False.
19.A float variable is a number with no fractional parts.
Answer: False.
20.How many digits after the decimal point does a float go on for? Any exceptions? How about a double var?
Answer: A float var supports about 6 digits after the decimal, but it may go over the limit llike 3.33333347 due to vagaries in floating calculatations. A double var has the same exceptions as the float, but supports up to and around 13 digits.
21.To be continued...
Was there any mistakes? Thanx in advance.
|