Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-30-2005, 09:47 AM   #1 (permalink)
slashdot
Registered User
 
Join Date: Dec 2004
Posts: 43
slashdot is on a distinguished road
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.
slashdot is offline   Reply With Quote
Old 04-30-2005, 12:12 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Quote:
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.
Not anymore. This rule was dropped with the current ISO C++ (1998, built on C89) standard. The current ISO C (C99) standard dropped this rule as well.

Quote:
17.What statement makes sure that bool variables output “true” and “false”?

Answer: cout.setf(cout.boolalpha);
Unusual. Do one of these:
cout.setf(ios::boolalpha);
cout << boolalpha << mybool;


Quote:
8.What is an expression?

Answer: An expression is a statement involving any sort of mathematical operation, that gives (returns) a value.
No. It *may* return a value. See this from chapter 5 of the C++ standard:

Clause 5 defines the syntax, order of evaluation, and meaning of expressions. An expression is a sequence of operators and operands that specifies a computation. An expression can result in a value and can cause side effects.

Quote:
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.
For n1 in both cases, we can't say the word "change". The behaviour or unitialized or unassign variables is undefined. In each instance, change the word "initialze(d)" by "assign(ed)". There is a (important) difference between assigning and initializing.

Quote:
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.
Close.
The answer is *exactly* 6.
Quote:
A double var has the same exceptions as the float, but supports up to and around 13 digits.
16

Becarefull with these things. The number of digits is implementation defined. So on a 4 bit system, you can forget so many digits.
__________________
Valmont is offline   Reply With Quote
Old 05-03-2005, 06:12 AM   #3 (permalink)
slashdot
Registered User
 
Join Date: Dec 2004
Posts: 43
slashdot is on a distinguished road
Thanx Val. I noticed I don't know what I read, and/or C++ for dummies is failing me. Either way I got it corrected so its all good.
slashdot is offline   Reply With Quote
Old 05-03-2005, 11:18 AM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
No primer will give you the deeper or correct insights. They mainly focus on "language learning". Best thing is to move on with it, and as you progress you'll find many more things to explore on your path. That's typical .
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
operate overloading member function in C# sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 02:36 AM
For those who have Learned C from "The C Programming Lanuage" DemosthenesB Standard C, C++ 5 07-13-2003 12:22 AM
edit? anon Lounge 10 11-21-2002 03:02 PM


All times are GMT -8. The time now is 01:20 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting