New Posts  All Forums:Forum Nav:

Test me on C++

post #1 of 32
Thread Starter 
Hey guys, I have a exam coming up soon so if you guys are board you can test me, I know my way up to classes.

Prefebbly code that does not require more then 6 lines to fix (code can be up 2 how ever long but if for example you want me to put an array in that fine but not expect to write a whole code).

example question
Code:
Given the following variables and statement, what value would be assigned to the variable e

 

C++

 

int a = 15;

int b = -20;

bool c = false;

bool d = true;

bool e = (a < b) || (d && !c);

Write a class which stores an array of 10 strings. The user should be able to add a new string, up to the limit, get a string back from some valid location, that is, one which contains a string, in the array, and print every valid element, each one on a new line.

You are asked to write a program to multiply all the values in an array of integers with a fixed value. Which language facility would you use and why?

When would you use inheritance?

Code:
What gets printed out by the following code:

 

C++

int n = 7;

int* p = &n;

n = 9

*p = 6;

cout <<  n/2 << endl;

You get the idea?
I know the answer to these between tongue.gif Helping me would be appreciated!
Edited by AnnoyinDemon - 4/21/14 at 5:51am
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
post #2 of 32
Are you looking for us to come up with questions for you to answer in the style of the ones above?
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
post #3 of 32
Thread Starter 
Quote:
Originally Posted by BradleyW View Post

Are you looking for us to come up with questions for you to answer in the style of the ones above?

Come up with some question tongue.gif Kinder yes please tongue.gif
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
post #4 of 32
post #5 of 32
QUESTION ONE:
Please look at the following code. Assume the code works correctly.
Code:

#include <iostream>
using namespace std;

int addNumbers();
int no1, no2, no3;

int main()
{

   cout << "Input First Number";
   cin >> no1

   cout << "Input Second Number";
   cin >> no2

   addNumbers();

   cout << no3;
}

int addNumbers()
{
   no3 = (no1 + no2);
}


Rewrite the code to eliminate the use of the global variables. (This will involve using local variables and the passing of variables between functions). (3 marks)



QUESTION TWO:
Look at the following code. You are to write down the errors you can see, and offer a solution to the errors. (5 marks)
Code:
#include <iomanip>
using namespace std;

int main()
{
   int number = 2.6;
   int number = int number + 5;
   cout >> number;
}


There are five errors present within the code. Ignore the absence of system ("pause"). You need to point out each error, explain why it is incorrect, and offer a solution. Remember, some of the errors in the code can have multiple solutions. Please provide only 1 solution for each error.
Edited by BradleyW - 4/21/14 at 10:56am
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
post #6 of 32
Thread Starter 
Code:

#include <iostream>
using namespace std;

int addNumbers(int no1, no2);
{
int no3=no1+no2;
return no3
}

int main()
{


  cout<< addNumbers(1,2);


}

I think I failed that question
QUESTION TWO:
Look at the following code. You are to write down the errors you can see, and offer a solution to the errors. (5 marks)
Code:
#include <iomanip>
using namespace std;

int main()
{
   double number = 2.6;
   double number = double number + 5;
   cout >> number;
}

1. int number should be double as it using points.
2. double number was reused, could call it double addnum
3. cout as >> when its ment to be << as we are not inputting but outputting.
4. could that be an error ""?
5. im terrible lol

well I gave a try and rep added !
Edited by AnnoyinDemon - 4/21/14 at 12:16pm
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
post #7 of 32
Quote:
Originally Posted by AnnoyinDemon View Post

Code:

#include <iostream>
using namespace std;

int addNumbers(int no1, no2);
{
int no3=no1+no2;
return no3
}

int main()
{


   addNumbers(1,2);


}
I think I failed that question
QUESTION TWO:
Look at the following code. You are to write down the errors you can see, and offer a solution to the errors. (5 marks)

[code]
#include <iomanip>
using namespace std;

int main()
{
   double number = 2.6;
   double number = double number + 5;
   cout >> number;
}

1. int number should be double as it using points.
2. double number was reused, could call it double addnum
3. cout as >> when its ment to be << as we are not inputting but outputting.
4. could that be an error ""?
5. im terrible lol

well I gave a try and rep added !
Write me a program that will add two numbers together and store the last 5 numbers which can be called upon using the word Last + whichever number between 1-5.
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
post #8 of 32
Thread Starter 
[/code]
Quote:
Originally Posted by ADHDadditiv View Post

Write me a program that will add two numbers together and store the last 5 numbers which can be called upon using the word Last + whichever number between 1-5.

I am embarrassed to show my code so maybe you can show me, i ended up having to go to visual basic and trying my own code lol which came with a lot of crazy errors.
I know we need a array ( int anArray[5] ), for loop, and a else statment letting the user select the number ?I failed lol
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Reply
post #9 of 32
Quote:
Originally Posted by AnnoyinDemon View Post

[/code]
I am embarrassed to show my code so maybe you can show me, i ended up having to go to visual basic and trying my own code lol which came with a lot of crazy errors.
I know we need a array ( int anArray[5] ), for loop, and a else statment letting the user select the number ?I failed lol
Oh god its been a while, I'll try though.
Code:
int addNumbers(no1, no2)
{
int no3=no1+no2;
return no3
int anArray[5] (something to do with no3 going into the array)
}
int show(Last)
{
Main = Last(call from the Array);
return =  Main;
Thats probably wrong, but it should be close.
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
post #10 of 32
You did OK, don't worry.

Let's concentrate on QUESTION TWO for now!
You spotted a few errors which is great!
Here is a full list of errors:

1) #include (This has no use for the program. If anything, we need #include to allow cout and cin functions). (1 ERROR)
2) int number = 2.6 (Correct, int would not work due to the decimal precision. We would need double, or float would do). (1 ERROR)
3) int number = int number + 5 (Again, correct. There are two errors here. Both the int's need to be removed). (2 ERROR's)
4) cout >> number; (Yep, the ">>" is the wrong way round). (1 ERROR)


You did well man!
Here is a fixed version of the code (Take a look):
Code:
#include <iostream>          //Fixed
using namespace std;
int main()
{
double number (2.6);          //Fixed
number = number + 5;       //Fixed 
cout << number;                 //Fixed
}

Take another look at QUESTION ONE.
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming