Help on this pls

• 06-17-2006
watsoncode
Help on this pls
These are not homework but some short problem question in my pdf notes with no answer. i am having a short quize/test soon and my teacher is away so i can only get help online. So anyone kind enough to help me on the solution. it should be easy because its not like i want the entire programming done. But its a bit of questions involve.

Heres the pdf notes i am using. Please d/l it here:

http://www.yousendit.com/transfer.ph...3BD3D745F29032

Go to: pg179,B 1to4
pg180,C1to3
pg182, B3,B4....Section C, C1,C2
pg184,B1a)b)c)d) and B2...Section C ,C1
pg188,B1,C1,C2
pg190,B1,B2,B3
pg191,C1a)b)
-----------------------------------------------------------------------
• 06-17-2006
Salem
How about you copy/paste the actual questions which are causing you some difficulty rather than us having to d/l a 200 page (SPRG%20ver2_4.pdf (3343 KB)) document just to look at 5 questions.
• 06-17-2006
watsoncode
its not 5 questions but a few sub ones but i post anyway. i know some of the answer but just wated to confirm my answers.

B3. Why is it easier to program in high-level languages than in machine
language or assembly language?
B4. Where are programs stored in a computer system?
C1. What are the errors (if any) in the following lines of C++ code:
Code:

```main() int step, start, stop = 100; step = 5; start = 10.5;```
C2. Can a compiler tell if a program will do exactly what is expected of it?
(i.e. can it find logical programming errors?) Give reasons for your
C3. What are the errors (if any) in the following lines of C++ code:
Code:

```int my pay; Double salary; int num1; num2; char 2answers;```
B3. How much memory (in bytes) is occupied by each of the following
variables?
double number; int count, index; char yesno;
B4. What is the output of the following code segment?
Code:

```int num = 100; cout << “Decimal : “ << dec << num << “\n”; cout << “Octal : “     << oct << num << “\n”; cout << “Hexa : “     << hex << num << “\n”;```
Section C: C++ language Syntax & Debugging
C1. Why are include files like <iostream> needed?
C2. Spot and correct the errors in the following code:
Code:

```#include <iostream> using namespace std; #include <iomanip> #define PI=3.14 Main() { int count; double colorVal cout << “Enter an integer number ; cin >> “count” ; colorVal = PI*count; cout << "\nThe color value is : " << setw(8)     << fix << setprecision(2) << colorVal; }```
B1. Evaluate the following expressions:
(a) 21 % 4 % 2 * 3 + 2
(b) 25 % 3 + 2
(c) 18 + (5==5) * 10 % 4
(d) 5/2 + (85 >= 86)
B2. Study the following code and write the output.
Code:

```main() {  int x, y, z=4; y = (7+6) % 5 / 2; cout << y << “\n” ; z *= 3 + 2; cout << z << “\n” ; x=y==z; cout << x << “\n” ; }```
Section C: C++ language Syntax & Debugging
C1. Will the compiler give any error for the following code?
Code:

```double temp; cout << “Enter a floating point number :”; cin << temp;```
B1. Consider the code given below:
Code:

```int direction; if (direction == 1) cout << “Robot moving left\n”; else if (direction == 2) cout << “Robot moving right\n”; else if (direction == 3) cout << “Robot moving up\n”; else if (direction == 4) cout << “Robot moving down\n”; else cout << “Robot standing still\n”;```
Re-write the above code using a switch statement.

Section C: C++ language Syntax & Debugging
C1. What is wrong (if anything) with the following code?
Code:

```x=80; if (x = 100) cout << "Excellent" ;```
C2. Determine the errors in the following program.
Code:

```main() { int a=5, b=10; char operation; cout<<“Enter the operation [+, -, * or /]:); cin >> operation ; switch (operation) case ‘+’ : c = a+b; case ‘-’ : c = a-b; case ‘*’ : c = a*b; case ‘/’ : c = a/b; }; cout << a << operation << b <<”=”<< c; }```
Section B: Programming Concepts
B1. What will be the output of the following code:
Code:

```int i; for(i=10; i<20; i=i+2) { cout << i*10 ; }```
B2. Rewrite the code in B1 using a while loop

B3. What is the output of the following code?
Code:

```int count = 1, odd = 0; do { if ( (count % 2) != 0 ) odd++; count++; }while (count<10); cout << “odd = “ << odd;```
Section C: C++ language Syntax & Debugging
C1. Spot and correct the errors in the following code segments:
(a)
Code:

```int num; for(num=1, num<=10, num=num+1) { cout << “The square of num is : << num*num ; }```
(b)
Code:

```char input; double voltage current; while (input = y); { cout << “Enter the voltage and current : “; cin >> voltage >> current; cout << “The resistance is ” << voltage/current; cout << Do you wish to continue [y/n] : “; input << cin ; }```
• 06-17-2006
Salem
> i know some of the answer but just wated to confirm my answers.
OK, so what are your answer(s) so far, then we can tell you whether you got them right or not.
• 06-17-2006
watsoncode
Quote:

Originally Posted by Salem
> i know some of the answer but just wated to confirm my answers.
OK, so what are your answer(s) so far, then we can tell you whether you got them right or not.

yeah i know a few 2 or 3 question only. just some guess. i am a beginner in C++.
eg.like C1, start is double(undeclared)
• 06-17-2006
Sfel
Quote:

Originally Posted by watsoncode
yeah i know a few 2 or 3 question only. just some guess. i am a beginner in C++.
eg.like C1, start is double(undeclared)

Hint: try running it with your compiler and see what happens. You can answer all of these[except maybe those where you have to rewrite things] if you just put them in a compiler, hit run and see what happens and what errors, if any, you get.

Trial and error is worth a thousand explanations.
• 06-17-2006
cboard_member
>> Trial and error is worth a thousand explanations.

I like that. In fact, it's going in my signiture. It's just so true.
:)
• 06-17-2006
SlyMaelstrom
Quote:

Originally Posted by ahluka
>> Trial and error is worth a thousand explanations.

I like that. In fact, it's going in my signiture. It's just so true.
:)

I actually don't agree with it, personally, but if you're compiling someone else's code to see if it works real quick, it's fine.