Category Archives: Upwork General Programming

Upwork General Programming

Delphi 6 Test 2016

Published by:

1. Which of the following are the valid DeviceType property values for the TMediaPlayer component?

Answers:

  1. dtAutoSelect
  2. dtMP3
  3. dtExternalDevice
  4. dtAudio
  5. dtTV
  6. dtMPEG3
  7. dtDAT
  8. dtDigitalVideo

2. Which of the following are valid identifier names for a variable?

Answers:

  1. Cust_no5
  2. Cust no5
  3. 5Cust_No
  4. cUSTNo
  5. custno 5
  6. cust&no

3. TDataSet is a base class from which other database components are inherited to encapsulate which database object(s)?

Answers:

  1. A Table
  2. A Trigger
  3. A Field
  4. A Query
  5. A DBAware Component
  6. A Stored Procedure

4. Which of the following will add text to a TMemo component called Memo1?

Answers:

  1. Memo1.Lines.Add(‘Text’);
  2. Memo1.AddLine(‘Text’);
  3. Memo1.Lines.Include(‘Text’);
  4. Memo1.Lines.Append(‘Text’);

5. What is the purpose of the AutoMerge property in the TMainMenu component?

Answers:

  1. It determines if main menus of secondary forms merge with the main menu of the main form in non-MDI applications at runtime
  2. It determines if sub menu items are automatically merged with the parent menu items if there is only a single sub menu item
  3. It determines if the main menu items can be automatically resized at runtime so that they provide a “best fit” in a resizable form
  4. It determines if the TMainMenu component can correct menu item short cut key conflicts with existing Windows short cut keys

6. What component is used to link two datasets in a master/detail relationship?

Answers:

  1. TTable
  2. TDataSource
  3. TMasterDetail
  4. TDatabase

7. Which of the following will link a TUpDown control named UpDown1 with an Edit box named Edit1, allowing the TUpDown control to modify the values in the Edit box?

Answers:

  1. UpDown1.Associate := Edit1;
  2. UpDown1.Link := Edit1;
  3. UpDown1.Link(Edit1);
  4. Link(UpDown1,Edit1);

8. What is the purpose of the “Break” procedure?

Answers:

  1. It causes the flow of control to exit the current function or procedure and execute the next logical code statement
  2. It causes the current thread to suspend execution to allow other threads to operate
  3. It simulates the user pressing the Break key on the keyboard
  4. It causes the flow of control to exit a loop and continue at the next statement following the loop

9. For a TQuery component called Query1 with SQL of “Select * from Student Where Number=500”, which of the following is the correct method to run the query?

Answers:

  1. Query1.Active:=True;
  2. Query1.RunSQL;
  3. Query1.ExecuteAction(SQL);
  4. Query1.ExecSQL;

10. What does the Cancel property of the TButton object do?

Answers:

  1. It automatically displays Cancel as the button caption
  2. It determines if the button’s OnClick event handler is called when the Escape key <Esc> is pressed on the keyboard
  3. It calls the parent forms’ OnClose event
  4. It causes a popup menu to be displayed when the button is clicked which permits the user to select Cancel

11. Which property of TBitBtn allows you to specify what image to display on the button?

Answers:

  1. BitBtn1.CaptionImage
  2. BitBtn1.Image
  3. BitBtn1.Glyph
  4. BitBtn1.Picture

12. What is the value of the variable int_temp after the for loop has ended in the code shown?

Answers:

  1. 1
  2. 2
  3. 5
  4. The value of int_temp is undefined

13. Which of the following will connect a DataSource to a Table where the Datasource component is call DataSource1 and the Table component is called Table1?

Answers:

  1. DataSource1.Table:=Table1;
  2. DataSource1.DataSet:=Table1;
  3. DataSource1.Source:=Table1;
  4. DataSource1.SetTable(Table1);

 

14. Which of the following is a event of TPanel?

Answers:

  1. OnClose
  2. OnExit
  3. OnTerminate
  4. OnDoubleClick

15. Given the code “Edit1.Hint := ‘Customer Name|Enter Customer Name in the edit box’;”, which of the following is the correct code to retrieve the text after the | character, i.e. “Enter Customer Name in the edit box”, when the OnHint handler is called?

Answers:

  1. GetLongHint(Application.Hint);
  2. GetHint(Application.Hint);
  3. GetShortHint(Application.Hint);
  4. GetSecondHint(Application.Hint);

16. Which three properties of TProgressBar are responsible for setting the minimum, maximum and current position for the control?

Answers:

  1. Maximum, Minimum & Percentage
  2. Maximum, Minimum & Position
  3. Max, Min & Position
  4. Max, Min & Pos

17. What does the code shown do?

Answers:

  1. Creates an array to store two Integers
  2. Creates an array to store two Variants
  3. Creates an array to store one hundred Integers
  4. Creates an array to store ninety nine Integers

18. What happens if the TreeView1.Items list is empty when the code “TreeView1.Items.AddFirst(TreeView1.Items[0],’X’);” is executed?

Answers:

  1. An X appears as the top most node in the TreeView
  2. An “Index is out of bounds” error message is displayed
  3. An ETreeViewError exception is raised with the message ‘Invalid Index’
  4. An X appears as a sub node to the first node in the TreeView

19. Given a TPageControl component called PageControl1 with three TabSheets called TabSheet1, TabSheet2 and TabSheet3 (in that order), which of the following will make TabSheet2 selected?

Answers:

  1. PageControl1.TabIndex:=1;
  2. TabSheet2.Show;
  3. PageControl1.ShowTab(TabSheet2);
  4. PageControl1.VisibleTab:=TabSheet2;
  5. TabSheet2.Click;
  6. TabSheet2.Select(PageControl1);

20. Given that x and y are variables declared as type Char, which of the following is NOT a valid Pascal assignment statement?

Answers:

  1. x := y;
  2. x := Char(Ord(Y)+1);
  3. x := Char(#22);
  4. x := y + #22;

21. Which of the following is the correct code to cause a popup menu named Popupmenu1 on a form called Form1 to be displayed?

Answers:

  1. Application.DisplayMenu(Form1.Popupmenu1);
  2. Form1.Popupmenu1.Popup(20,30);
  3. Form1.Popupmenu1.ShowMenu;
  4. Form1.ShowMenu(Popupmenu1);

22. How does a TRichEdit differ from a TMemo?

Answers:

  1. TRichEdit prevents users from overwriting existing text, whereas TMemo does not
  2. TRichEdit allows saving directly to text files, whereas TMemo does not
  3. TRichEdit prevents font attributes from being changed by the user, whereas TMemo does not
  4. TRichEdit allows font attributes to be set, whereas TMemo does not

23. Which of the following is the correct method to activate a modal open dialog box when using the TOpenDialog component?

Answers:

  1. OpenDialog1.OpenFile;
  2. OpenDialog1.GetFile;
  3. OpenDialog1.Filename;
  4. OpenDialog1.Execute;

24. Which of the following is the correct code to create an object from class TMainForm?

Answers:

  1. Form.Create(TMainForm);
  2. Application.CreateForm(TMainForm, MainForm);
  3. TMainForm.CreateForm(MainForm);
  4. MainForm:=Application.CreateFormInstance(TMainForm);

25. What files end with the .dpk extension?

Answers:

  1. Unit Source files
  2. Project Source files
  3. Package Source files
  4. Delphi Library

26. What is the main difference between TLabel and TStaticText?

Answers:

  1. TStaticText has a Window Handle and can accept focus whereas TLabel does not have a Window Handle and cannot accept focus
  2. TStaticText allows the user to edit the text displayed whereas TLabel does not allow the user to edit the text displayed
  3. TLabel’s caption property can be changed programmatically whereas TStaticText’s Caption property cannot be changed programmatically
  4. TLabel does not have a ShowAccelChar property whereas TStaticText does have a ShowAccelChar property

27. Which of the following changes a TDBNavigator component called DBNavigator1 so that it only displays navigation buttons?

Answers:

  1. DBNavigator1.VisibleButtons := [nbFirst,nbLast,nbPrior,nbNext];
  2. DBNavigator1.NavigationOnly := True;
  3. DBNavigator1.Buttons := [nbFirst,nbLast,nbPrior,nbNext];
  4. DBNavigator1.Constraints := [nbFirst,nbLast,nbPrior,nbNext];

28. Which of the following retrieves the value from the SNumber field as a string for the current record in an open Table called Table1?

Answers:

  1. Table1.Field.SNumber.AsString;
  2. String(Table1.Fields(‘SNumber’));
  3. Table1.FieldByName(‘SNumber’).AsString;
  4. Table1.Items.String(‘SNumber’);

29. What value is displayed on screen when the procedure test is called?

Answers:

  1. 5
  2. 13
  3. 8
  4. 3

30. What is the purpose of the Alignment Palette?

Answers:

  1. To change the order or position of the components in the Visual Component Library
  2. To align the main IDE Windows to each other
  3. To align components to the form, or with each other
  4. To set the alignment property of any components on a form

31. Which of the following would cause all the items in a RadioGroup to be appended so that all items appear twice?

Answers:

  1. Radiogroup1.Items.Duplicate;
  2. Radiogroup1.Append(Radiogroup1);
  3. Radiogroup1.Items.Append(rgALL);
  4. Radiogroup1.Items.AddStrings(Radiogroup1.Items);

32. Which of the following is the correct code to cause a form named Form1 to be displayed as modal?

Answers:

  1. Form1.Show;
  2. ShowModal(Form1);
  3. Form1.ModalResult:=mrOk
  4. Form1.ShowModal;

33. Which of the following is the correct code to “tick” a TCheckBox component called CheckBox1 as shown?

Answers:

  1. CheckBox1.Checked:=True;
  2. CheckBox1.Ticked:=True;
  3. CheckBox1.Tick(True);
  4. CheckBox1.Enabled:=True;

34. What does the TDBLookupComboBox component do?

Answers:

  1. It allows a field value to be selected from a TList object specified by the programmer
  2. It performs a search for a field with the same name as the text entered
  3. It allows the selection of a database from a list of those found on a network
  4. It identifies a set of field values in one dataset with a corresponding set of values from another dataset

35. From the code shown, how many times would the ShowMessage procedure be called if the button in question was clicked three (3) times?

Answers:

  1. 0
  2. 1
  3. 2
  4. 3

36. In the code shown, TMyClass inherits from which parent class?

Answers:

  1. TApplication
  2. TObject
  3. Inheritance does not take place
  4. TMyClass

37. Which of the following removes the SQL statement from a TQuery component called Query1?

Answers:

  1. Query1.SQL.Delete;
  2. Query1.Delete(SQL);
  3. Query1.SQL.Clear;
  4. Query1.Enabled:=False;

38. What does the code shown do?

Answers:

  1. Loads the number 1 into the DH register
  2. Loads the number 1 into the dh variable
  3. Loads the character ‘1’ into the dh variable
  4. Loads the value in the dh variable into the DH register

39. Which of the following is NOT an event of the TApplicationEvents component?

Answers:

  1. OnActionExecute
  2. OnBusy
  3. OnMessage
  4. OnHint
  5. OnException
  6. OnSettingChange

40. When will the code “Application.Terminate;” be executed in the code shown?

Answers:

  1. When the user presses the Cancel button
  2. Every time the procedure is executed
  3. When the user presses the Ok button
  4. Never

41. What is the shortcut key for manually displaying the code completion window while entering code?

Answers:

  1. CTRL + SPACE
  2. CTRL + ESC
  3. CTRL + ALT + TAB
  4. CTRL + Page Down

42. The TTimer component has a property which determines how frequently the OnTimer event occurs. Which of the following is that property and what does the property measure?

Answers:

  1. Property: Time, Measured in: Seconds
  2. Property: Timer, Measured in: Hundreds of a second (1/100 Sec)
  3. Property: Interval, Measured in: Milliseconds (1/1000 Sec)
  4. Property: Tick, Measured in: Clock Ticks

43. Given a ComboBox named ComboBox1 and an Edit box named Edit1, which of the following is the correct code to add the information in the Edit box to the drop down list in the ComboBox?

Answers:

  1. ComboBox1.Items.Add(Edit1.Text);
  2. ComboBox1.Strings := ComboBox1.Strings + Edit1.Text;
  3. ComboBox1.List.AddItem(Edit1.Text);
  4. ComboBox1.Append(Edit1.Text);

44. Which of the following properties when set to True, enables an application to gain sole access to a database?

Answers:

  1. TDatabase.OthersReadOnly
  2. TDatabase.KeepConnection
  3. TDatabase.Params
  4. TDatabase.Exclusive

45. What is the purpose of Code Templates?

Answers:

  1. To provide easy access to commonly used programming statements
  2. To allow the creation of Document Templates from existing source code
  3. To provide easy access to Native Databases without using components
  4. To allow the conversion of selected code to a procedure

46. What does the procedure shown do?

Answers:

  1. It moves the contents of the file c:autoexec.bat to the file c:outfile.txt
  2. It moves the contents of the file c:outfile.txt to the file c:autoexec.bat
  3. It copies the contents of the file c:autoexec.bat to the file c:outfile.txt
  4. It copies the contents of the file c:outfile.txt to the file c:autoexec.bat

47. What is the purpose of the TDataModule?

Answers:

  1. To provide a login to a secured or an encrypted database
  2. To provide a temporary storage area of query results
  3. To provide a location for centralized handling of non-visual components
  4. To provide a connection to a remote database server

48. What is the purpose of the AlphaBlend property of TForm?

Answers:

  1. It specifies the background color of the form
  2. It specifies if the form is translucent or not
  3. It specifies if the form is available for drawing on via TCanvas
  4. It specifies the redrawing speed of the form

49. What is the purpose of the Initialization section of a Unit?

Answers:

  1. It contains assembly code that is executed on PC startup
  2. It contains statements that are executed on unit start up
  3. It contains Window handling code
  4. It contains program management code and should not be edited directly by a programmer

50. Which key toggles between the Object Inspector and the Edit Window / Form?

Answers:

  1. ALT + O
  2. F11
  3. F4
  4. CTRL + ALT + TAB

656 total views, 4 views today

Upwork General Programming

Cocoa programming for Mac OS X 10.5 Test 2016

Published by:

1. What is true regarding notifications?

Answers:

  1. They can be dispatched to only one object
  2. The object posting the notification does not even have to know whether the observer exists
  3. An object may receive any message you like from the notification center, not just the predefined delegate method
  4. All of the above
  5. None of the above

2. Which of the following retrieves the application main bundle?

Answers:

  1. [NSBundle mainBundle]
  2. [NSApplication mainBundle]
  3. [NSApp mainBundle]
  4. None of the above

3. Can you use NSLock on a POSIX mutex?

Answers:

  1. Yes
  2. No

4. If you spawn a thread with POSIX thread api, will Cocoa be notified?

Answers:

  1. Yes
  2. No

5. What method should be called before you are able to draw in the drawRect: method of a view?

Answers:

  1. None
  2. lockFocus
  3. lockView
  4. prepareDrawing
  5. None of the above

6. Which of the following creates an autoreleased array?

Answers:

  1. [NSMutableArray array];
  2. [NSMutableArray new];
  3. [[NSMutableArray alloc] init];

7. What class should be used to load resources?

Answers:

  1. NSResource
  2. NSApplication
  3. NSBundle
  4. NSFile
  5. None of the above

8. Can an object marked for autorelease be retained?

Answers:

  1. Yes
  2. No

9. What is a notification?

Answers:

  1. A user event
  2. A special message type used within the kernel
  3. An object that encapsulates information about an event
  4. None of the above

10. Fill the blank.

NSView : <> : NSObject

Answers:

  1. NSWindow
  2. NSResponder
  3. NSResponder : NSWindow
  4. NSRootView
  5. NSRoot

11. If you call interpretKeyEvents:, which of the following method is likely to be called?

Answers:

  1. collectEvent:
  2. dispatchEvent:
  3. sendEvent:
  4. insertText:/li>
  5. None of the above

12. Where is the (0,0) coordinate located on the screen?

Answers:

  1. top-left
  2. top-right
  3. bottom-left
  4. bottom-right
  5. center

13. What method should be called before you are able to draw outside the drawRect: method of a view?

Answers:

  1. None
  2. lockView
  3. lockFocus
  4. prepareView
  5. None of the above

14. What will be the output of the following code?

NSRect rect = NSMakeRect(0, 0, 10, 10);
NSRect *rect2 = malloc(sizeof(*rect2));
if(!rect2) {
NSLog(@”Not enough memory.”);
exit(EXIT_FAILURE);
}

*rect2 = rect;

printf(“%dn”, rect.size.width);

Answers:

  1. 0
  2. 10
  3. RUNTIME ERROR
  4. COMPILATION ERROR
  5. None of the above

15. Can NSBundle be used to load Java code?

Answers:

  1. Yes
  2. No

16. Under Mac OS X 10.5, CGRect, CGSize and CGPoint have the same structure as NSRect, NSSize and NSPoint respectively. Is it true?

Answers:

  1. Yes
  2. No

17. What is an observer?

Answers:

  1. An object that implements the NSObserver protocol
  2. An object that sends a notification
  3. An object that receives ALL notifications
  4. An object registered with the notification center
  5. None of the above

18. Does Cocoa support 64bits?

Answers:

  1. Yes
  2. No

19. Why is CGFloat recommenced to be used instead of float?

Answers:

  1. They are the same; so it’s done only to make the code look nicer.
  2. CGFloat is a special structure used to do arbitrary number computation.
  3. For 64bit compatibility.
  4. None of the above

20. Can resources be localized?

Answers:

  1. Yes
  2. No

21. Fill the blank.

NSMutableArray : <> : NSObject

Answers:

  1. NSSet
  2. NSCollection
  3. NSArray
  4. NSContainer
  5. NSMovableArray

22. What is NSRect?

Answers:

  1. A class
  2. An object
  3. A structure
  4. A C built in type
  5. An Objective-C built in type

23. Fill the blank.

NSCountedSet : <> : NSObject

Answers:

  1. NSArray : NSClass
  2. NSMutableArray : NSArray
  3. NSMutableSet : NSSet
  4. NSSet
  5. NSSet : NSArray

24. Can NSDistributedNotificationCenter be used to communicate between multiple machines?

Answers:

  1. Yes
  2. No

25. Is the following code correct?

NSMutableArray *a = [NSMutableArray new];

// do something with a

[a release];

Answers:

  1. Yes
  2. No

26. What threading API should be used in Cocoa?

Answers:

  1. CFThread
  2. pthread
  3. pth
  4. NSThread
  5. None of the above

27. Is the following code correct?

NSMutableArray *a = [NSMutableArray array];

// do something with a

[a release];

Answers:

  1. Yes
  2. No

28. How can you move a view?

Answers:

  1. You cannot
  2. By calling move: method
  3. By changing the frame with setFrame:
  4. None of the above

29. Fill the blank.
NSButton : <> : NSObject

Answers:

  1. NSControl :
  2. NSWidget : NSView : NSResponder
  3. NSResponder
  4. NSWidget
  5. NSControl : NSView : NSResponder

30. How is a GUI usually created in Cocoa?

Answers:

  1. With interface builder
  2. By editing xml files manually
  3. Programmatically
  4. None of the above

31. Is it possible to create events and dispatch them to the application?

Answers:

  1. Yes
  2. No

32. Can POSIX thread be used in Cocoa?

Answers:

  1. Yes
  2. No

33. Is it correct to have sibling views overlapping?

Answers:

  1. Yes
  2. No

34. Is the following code valid?

NSSize s = NSMakeSize(10, 10);

int values[20];

values[s.height] = 5;

Answers:

  1. Compile error
  2. Runtime error
  3. Valid code

35. In a typical Cocoa application, do you have to manage your runloop yourself?

Answers:

  1. Yes
  2. No

36. Is NSString mutable?

Answers:

  1. Yes
  2. No

37. Can you use malloc/free in a Cocoa application?

Answers:

  1. Yes
  2. Yes, but only in a separate C library
  3. Yes, but we can use only malloc; free is not needed
  4. No

38. What is NSViewHeightSizable constant used for?

Answers:

  1. Transparency
  2. Scrolling
  3. Autoresizing
  4. Magnification
  5. None of the above

39. Can poll() be used to fetch Cocoa events?

Answers:

  1. Yes
  2. No

40. What is a toll-free bridged class?

Answers:

  1. A superclass of another class
  2. A class that can be interchanged with another class by casting
  3. A wrapper around another class
  4. A class with no memory need
  5. None of the above

41. What is Cocoa?

Answers:

  1. A language
  2. A tree
  3. A system
  4. A framework
  5. None of the above

42. Is NSRunLoop thread safe?

Answers:

  1. Yes
  2. No

43. Which of the following platforms supports Cocoa?

Answers:

  1. Windows
  2. Linux
  3. Mac OSX
  4. Solaris
  5. None of the above

44. In which language is Cocoa written?

Answers:

  1. C
  2. Objective-C
  3. C++
  4. Java
  5. Ruby

45. Where should application resources be usually put?

Answers:

  1. In /System
  2. In /Library
  3. Within the application’s bundle
  4. In /Resources
  5. None of the above

46. Is there a double click event?

Answers:

  1. Yes
  2. No

47. Can an object be the delegate of multiple objects?

Answers:

Yes

No

48. Is it mandatory to create an NSAutoreleasePool in a Cocoa application?

Answers:

  1. Yes
  2. No

49. What is the normal way of handling Cocoa events?

Answers:

  1. By polling for events
  2. By registering an event watcher
  3. By implementing NSResponder methods in subclasses
  4. None of the above

50. Which of the following classes manages the computer’s global notifications?

Answers:

  1. NSNotificationCenter
  2. NSDistributedNotificationCenter
  3. NSGlobalNotificationCenter
  4. NSSystemNotificationCenter

51. Can a notified object find out from where the notification is coming? (Sending object)

Answers:

  1. Yes
  2. No

52. How wide is unichar on a 32bit machine?

Answers:

  1. 8bit
  2. 16bit
  3. 32bit
  4. 64bit
  5. 128bit

53. Is the following code correct?

NSRect a = NSMakeRect(0, 1, 2, 3) + NSMakeRect(0, 1, 2, 3);

Answers:

  1. Yes
  2. No

54. Fill the blank.

NSNotification : <> : NSObject

Answers:

  1. NSEvent
  2. NSCenter
  3. NSDistributed
  4. NSGeneralNotification
  5. Nothing is required to fill the blank

55. Is the following code valid?

NSRect r;

r.size = NSMakeSize(10, 10);
r.origin = NSMakePoint(-5, -5);

Answers:

  1. Yes
  2. No

56. Is the following code correct?

NSMutableArray *a = [[NSMutableArray new] autorelease];

// do something with a

[a release];

Answers:

  1. Yes
  2. No

57. What kind of memory management mechanisms can Cocoa uses?

Answers:

  1. Garbage collection
  2. Reference counting
  3. Manual memory management
  4. None of the above

58. Can you detach threads in Cocoa?

Answers:

  1. Yes
  2. No

59. Which of the following is a valid Uniform Type Identifier?

Answers:

  1. JPEG
  2. .jpg
  3. public.jpeg
  4. image/jpeg
  5. .jpeg

60. Is the following code correct?

– (void)myMethod:(NSString **)s {
*s = [[NSString alloc] init]:
}

Answers:

  1. Yes
  2. No

878 total views, 2 views today

Upwork General Programming

C++ Programming Test 2016

Published by:

1. Consider the following class hierarchy:
class Base

{

}
class Derived : public Base

{

}
Which of the following are true?

Answers:

  1. The relationship between the Base and Derived can be described as: Base is a Derived
  2. The relationship between the Base and Derived can be described as: Base has a Derived
  3. Derived can access only public member functions of Base
  4. Derived can access public and protected member functions of Base
  5. The following line of code is valid: Base *object = new Derived();

2. Which of the following sets of functions do not qualify as overloaded functions?

Answers:

  1. void fun(int, char *) void fun(char *,int)
  2. void x(int,char) int *x(int,char)
  3. int get(int) int get(int,int)
  4. void F(int *) void F(float *)
  5. All of the above are overloaded functions

3. Consider the sample code given below and answer the question that follows.
1 class Car

2 {

3 private:

4 int Wheels;

5

6 public:

7 Car(int wheels = 0)

8 : Wheels(wheels)

9 {

10 }

11

12 int GetWheels()

13 {

14 return Wheels;

15 }

16 };

17 main()

18 {

19 Car c(4);

20 cout << “No of wheels:” << c.GetWheels();

21 }
Which of the following lines from the sample code above are examples of data member definition?

Answers:

  1. 4
  2. 7
  3. 8
  4. 14
  5. 19

4. Which of the following statements about function overloading, is true?

Answers:

  1. C++ and namespaces should be used to replace occurrences of function overloading
  2. Overloaded functions may not be declared as “inline”
  3. Although the return types and parameter types of overloaded functions can be different, the actual number of parameters cannot change
  4. Function overloading is possible in both C and C++
  5. The parameter lists and const keyword are used to distinguish functions of the same name declared in the same scope

5. Consider the sample code given below and answer the question that follows.
class Shape
{
public:
virtual void draw() = 0;
};

class Rectangle: public Shape
{
public:
void draw()
{
// Code to draw rectangle
}
//Some more member functions…..
};

class Circle : public Shape
{
public:
void draw()
{
// Code to draw circle
}
//Some more member functions…..
};

int main()
{
Shape objShape;
objShape.draw();
}
What happens if the above program is compiled and executed?

Answers:

  1. Object objShape of Shape class will be created
  2. A compile time error will be generated because you cannot declare Shape objects
  3. A compile time error will be generated because you cannot call draw function of class ‘Shape’
  4. A compile time error will be generated because the derived class’s draw() function cannot override the base class draw() function
  5. None of the above

6. Consider the sample code given below and answer the question that follows.
class Person

{

public:

Person();

virtual ~Person();

};

class Student : public Person

{

public:

Student();

~Student();

};
main()

{

Person *p = new Student();

delete p;

}
Why is the keyword “virtual” added before the Person destructor?

Answers:

  1. To make it impossible for this particular destructor to be overloaded
  2. To ensure that correct destructor is called when p is deleted
  3. To ensure that the destructors are called in proper orde
  4. To improve the speed of class Person’s destruction
  5. To prevent the Person class from being instantiated directly making it an abstract base class

7. What linkage specifier do you use in order to cause your C++ functions to have C linkage

Answers:

  1. extern “C”
  2. extern C
  3. _stdcall
  4. _cdecl
  5. _fastcall?

8. You want the data member of a class to be accessed only by itself and by the class derived from it. Which access specifier will you give to the data member?

Answers:

  1. Public
  2. Private
  3. Protected
  4. Friend
  5. Either Public or Friend

9. Consider the sample code given below and answer the question that follows.
class Person

{

string name;

int age;

Person *spouse;

public:

Person(string sName);

Person(string sName, int nAge);

Person(const Person& p);
Copy(Person *p);

Copy(const Person &p);

SetSpouse(Person *s);

};
Which one of the following are declarations for a copy constructor?

Answers:

  1. Person(string sName);
  2. Person(string sName, int nAge);
  3. Copy(Person *p);
  4. Person(const Person &p);
  5. Copy(const Person &p)?

10. Which of the following member functions can be used to add an element in an std::vector?

Answers:

  1. add
  2. front
  3. push
  4. push_back

11. Sample Code

typedef char *monthTable[3];

Referring to the code above, which of the following choices creates two monthTable arrays and initializes one of the two?

Answers:

  1. monthTable(winter,spring={“March”,”April”,”May”});
  2. monthTable winter, spring;
  3. monthTable, winter, spring;
  4. monthTable, winter,spring={“March”,”April”,”May”};
  5. monthTable winter,spring={“March”,”April”,”May”};

12. Which of the following are NOT valid C++ casts

Answers:

  1. dynamic_cast
  2. einterpret_cast
  3. static_cast
  4. const_cast
  5. void_cast

13. Consider the sample code given below and answer the question that follows:
<font size=2>
char **foo;
/* Missing code goes here */
for(int i = 0; i < 200; i++)
{
foo[i] = new char[100];
}

Referring to the sample code above, what is the missing line of code?
</font

Answers:

  1. font size=2>foo = new *char[200];</font
  2. font size=2>foo = new char[200];</font
  3. font size=2>foo = new char[200]*;</font
  4. font size=2>foo = new char*[200];</font
  5. font size=2>foo = new char[][200];</font

14. Consider the line of code given below and answer the question that follows.

class screen;

Which of the following statements are true about the class declaration above?

Answers:

  1. Incorrect syntax. The body of the class declaration is missing
  2. Incorrect syntax. {}; is missing
  3. The syntax is correct
  4. Incorrect syntax. {} is missing
  5. Incorrect syntax. Requires a *

15. Which of the following are true about class member functions and constructors?

Answers:

  1. A constructor can return values but a member function cannot
  2. A member function can declare local variables but a constructor cannot
  3. A member function can return values but a constructor cannot
  4. A constructor can declare local variables but a member function cannot
  5. A member function can throw exceptions but a constructor cannot

16. Consider the following code:

#include<stdio.h>

int main(int argc, char* argv[])
{
enum Colors
{
red,
blue,
white = 5,
yellow,
green,
pink
};

Colors color = green;
printf(“%d”, color);
return 0;
}

What will be the output when the above code is compiled and executed?

Answers:

  1. 4
  2. 5
  3. 6
  4. 7
  5. 8
  6. 9
  7. The code will have compile time errors

17. What access specifier allows only the class or a derived class to access a data membe

Answers:

  1. private
  2. protected
  3. default
  4. virtual
  5. public

18. Consider the following code:

#define SQ(a) (a*a)

int answer = SQ(2 + 3);

What will be the value of answer after the above code executes?

Answers:

  1. 10
  2. 11
  3. 25
  4. 13
  5. None of the above

19. What is the output of the following code segment?

int n = 9;

int *p;

p=&n;

n++;

cout << *p+2 << “,” << n;

Answers:

  1. 11,9
  2. 9,10
  3. 12,10
  4. 11,10

20. If input and output operations have to be performed on a file, an object of the _______ class should be created.

Answers:

  1. fstream
  2. iostream
  3. ostream
  4. istream
  5. None

21. In the given sample Code, is the constructor definition valid?
class someclass

{

int var1, var2;

public:

someclass(int num1, int num2) : var1(num1), var2(num2)

{

}

};

Answers:

  1. Yes, it is valid
  2. No, we cannot assign values like this
  3. No, the parenthesis cannot be empty
  4. No, var1 and var2 are not functions but are variables

22. Consider the sample code given below and answer the question that follows.

template <class T> Run(T process);

Which one of the following is an example of the sample code given above?

Answers:

  1. A non-template member function
  2. A template function definition
  3. A template function declaration
  4. A template class definition
  5. A template class declaration

23. Which of the following statements regarding functions are false?

Answers:

  1. Functions can be overloaded
  2. Functions can return the type void
  3. Inline functions are expanded during compile time to avoid invocation overhead
  4. You can create arrays of functions
  5. You can pass values to functions by reference arguments
  6. You can return values from functions by reference arguments
  7. A function can return a pointe

24. What does ADT stand for?

Answers:

  1. Accessible derived type
  2. Access to derived type
  3. Abstract data type
  4. Abstract derived type
  5. Accessible data type

25. Consider the following code:

#include<iostream>

using namespace std;

class A
{
public :

A()

{

cout << “Constructor of An”;

};

~A()

{

cout << “Destructor of An”;

};

};
class B : public A

{
public :

B()

{

cout << “Constructor of Bn”;

};

~B()

{

cout << “Destructor of Bn”;

};

};
int main()
{

B *pB;

pB = new B();

delete pB;

return 0;

}
What will be the printed output?

Answers:

  1. Constructor of B Constructor of A Destructor of A Destructor of B
  2. Constructor of A Constructor of B Destructor of B Destructor of A
  3. Constructor of B Constructor of A Destructor of B Destructor of A
  4. Constructor of A Constructor of B Destructor of A Destructor of B
  5. The sequence of construction and destruction of A and B will be compiler specific

26. Consider the following code:
<font size=2>
template<class T> void Kill(T *& objPtr)
{
delete objPtr;
objPtr = NULL;
}

class MyClass
{
};

void Test()
{
MyClass *ptr = new MyClass();
Kill(ptr);
Kill(ptr);
}
</font>
Invoking Test() will cause which of the following?

Answers:

  1. Code will Crash or Throw and Exception
  2. Code will Execute, but there will be a memory leak
  3. Code will execute properly
  4. Code will exhibit undefined behavio

27. Consider the following statements relating to static member functions and choose the appropriate options:

1. They have external linkage
2. They do not have ‘this’ pointers
3. They can be declared as virtual
4. They can have the same name as a non-static function that has the same argument types

Answers:

  1. All are true
  2. Only 1, 2 and 4 are true
  3. Only 1 and 2 are true
  4. Only 1,3 and 4 are true
  5. All are false

28. What will be the output of the following code?

class b

{
int i;

public:

virtual void vfoo()

{

cout <<“Base “;

}

};

class d1 : public b

{

int j;

public:

void vfoo()

{

j++;

cout <<“Derived”;

}

};

class d2 : public d1

{

int k;

};

void main()

{

b *p, ob;

d2 ob2;

p = &ob;

p->vfoo();

p = &ob2;

p->vfoo();

}

Answers:

  1. Base Base
  2. Base Derived
  3. Derived Base
  4. Derived Derived

29. Consider the following code:
class A {
typedef int I; // private member
I f();
friend I g(I);
static I x;
};
Which of the following are valid:

Answers:

  1. A::I A::f() { return 0; }
  2. A::I g(A::I p = A::x);
  3. A::I g(A::I p) { return 0; }
  4. A::I A::x = 0;

30. Consider the following code:
#include<iostream>

using namespace std;
int main()
{

cout << “The value of __LINE__ is ” <<__LINE__;
return 0;

}
What will be the result when the above code is compiled and executed?

Answers:

  1. The compilation will fail with the error – ‘__LINE__’ : undeclared identifie
  2. The compilation will fail with the error – ‘__LINE__’ unresolved identifie
  3. The code will compile and run without errors
  4. The code will crash at runtime

31. Which of the following STL classes is deprecated (i.e. should no longer be used)?

Answers:

  1. ostrstream
  2. ostringstream
  3. ostream
  4. wostream

2,462 total views, 4 views today

Upwork General Programming

C Programming Test 2016

Published by:

1. Identify the incorrect statement.

Answers:

  1. Records can be defined in C by using structures
  2. Structure members can be of the same/different data types
  3. Memory is reserved when a structure label is defined
  4. A pointer to a structure can be used to pass a structure to a function
  5. Arrays of structures can be defined and initialized

2. What will be printed on the standard output as a result of the following code snippet?
void func()

{

static int i = 1;

int j = 1;

i++;

j++;

printf(“%d %d “,i,j);

}
void main()

{

func();

func();

func();

}

Answers:

  1. 2 2 2 2 2 2
  2. 2 2 3 2 4 2
  3. 2 2 2 3 2 4
  4. 2 2 3 3 4 4
  5. None of these

3. Given the following array:

int a[8] = {1,2,3,4,5,6,7,0};
what would be the output of
printf(“%d”,a[4]); ?

Answers:

  1. 3
  2. 4
  3. 5
  4. 6
  5. 7

4. Which function will convert a string into an integer?

Answers:

  1. int()
  2. number()
  3. atoi()
  4. val()
  5. tonum()

5. Which standard function is used to clear memory allocated by the malloc() function?

Answers:

  1. free
  2. calloc
  3. delete
  4. elease
  5. destroy

6. From which of the following loop or conditional constructs, is “break” used for an early exit?

Answers:

  1. switch
  2. fo
  3. while
  4. do-while
  5. All of the above

7. What would be printed on the standard output as a result of the following code snippet?

char i = ‘A’;
char *j;
j = & i;
*j = *j + 32;
printf(“%c”,i);

Answers:

  1. An error will occur
  2. a
  3. A
  4. c

8. What does the argv[0] represent?

Answers:

  1. The first command line parameter has been passed to the program
  2. The program name
  3. The number of command line arguments
  4. None of the above

9. What would be printed on the standard output as a result of the following code snippet?

#define func(t, a, b) { t temp; temp=a; a=b; b=temp; }
main()
{
int a=3, b=4;
float c=4.5, d = 5.99;
func(int, a, b);
func(float, c, d);
printf(“%d %d “, a, b);
printf(“%.2f %.2fn”, c, d);
}

Answers:

  1. Results in Compilation Error
  2. 3 4 5.99 4.50
  3. 3 4 4.50 5.99
  4. 4 3 5.99 4.50
  5. None of the above

10. What is the function to concatenate two strings?

Answers:

  1. strcmp()
  2. strcpy()
  3. strcat()
  4. strlen()
  5. catstr()

11. Given the following array:

char books[][40]={
“The Little World of Don Camillo”,
“To Kill a Mockingbird”,
“My Family and Other Animals”,
“Birds, Beasts and Relatives”
};
what would be the output of printf(“%c”,books[2][5]);?

Answers:

  1. m
  2. M
  3. F
  4. i
  5. L

12. Which of the following is not a valid mode for opening a file?

Answers:

  1. r
  2. w
  3. a
  4. +
  5. i

13. Given the following array declaration:

int a[2][3][4]
what would be the number of elements in array a?

Answers:

  1. 24
  2. 22
  3. 20
  4. 12
  5. 36

14. Which function will convert a string into a double precision quantity?

Answers:

  1. atoi()
  2. atof()
  3. atol()
  4. atan()
  5. acos()

15. What will be the output of following code?

int main()
{
int i;
i = 0;
for (i = 1; i <2; i++)
{
i++;
printf( “%d”, i );
continue;
printf( “%d”, i );
}
return 0;
}

Answers:

  1. 22
  2. 2,2
  3. 2
  4. none of the above

16. What would be printed on the standard output as a result of the following code snippet?
main()

{

int u = 1, v = 3;

printf(“%d %d”,u,v);

funct1(&u,&v);

printf(“%d %dn”,u,v);

}
void funct1(int *pu, int *pv)

{

*pu=0;

*pv=0;

return;

}

Answers:

  1. 1 31 3
  2. 1 3 1 1
  3. 1 30 0
  4. 1 1 1 1
  5. 3 1 3 1

17. What will be printed on the standard output as a result of the following code snippet?

void main()
{
int num1 = 30, num2 = 4;
float result;
result = (float)(num1/num2);
printf(“%.2f”, result);
return 0;
}

Answers:

  1. 7
  2. 7.00
  3. 7.000000
  4. 7.5
  5. 7.50

18. Study the following code:
int n = 2;

int a[n];
What is the error in the above code?

Answers:

  1. There is no error
  2. The minimum limit of an array is 5
  3. The second statement should be placed before the first
  4. A constant value has to be given in place of a variable for array declaration

19. Which of the following is not a file related function?

Answers:

  1. fgetc()
  2. puts()
  3. fputc()
  4. fscanf()
  5. fprintf()

20. What is the output of the following program ?
main()

{
int u = 1, v = 3;

printf(“%d %d”,u,v);

funct1(&u,&v);

printf(” %d %dn”,u,v);

}
void funct1(int *pu, int *pv)

{

*pu=0;

*pv=0;
return;

}

Answers:

  1. 1 3 1 3
  2. 1 3 1 1
  3. 1 3 0 0
  4. 1 1 1 1
  5. 3 1 3 1

21. What would be printed on the standard output as a result of the following code snippet?

#include<stdio.h>
main()
{
unsigned char a=255;
a = a+1;
printf(“%d”,a);
return 0;
}

Answers:

  1. Undefined value
  2. 256
  3. 1
  4. -1

22. What is wrong with the following statement?

int func();

Answers:

  1. The function definition {…} is missing
  2. While calling a function, the type int is not needed
  3. No parameter has been passed
  4. The semicolon should not be there
  5. There is nothing wrong with the statement

23. Suppose there is a file a.dat which has to be opened in the read mode using the FILE pointer ptr1, what will be the correct syntax?

Answers:

  1. ptr1 = open(“a.dat”);
  2. ptr1 = fileopen(“a.dat”);
  3. ptr1 = fopen(“a.dat”,”r”);
  4. ptr1 = open(“a.dat”,”r”);
  5. ptr1 = fileopen(“a.dat”,”r”);

24. What would be printed on the standard output as a result of the following code snippet?
main()

{

char *pmessage = “asdfgh”;

*pmessage++;

printf(“%s”, pmessage);

return 0;

}

Answers:

  1. Will result in Compilation Error
  2. Undefined string
  3. sdfgh
  4. asdfgh

25. Study the following code where num is an integer array and n is the length of the array:

for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i] > num[j])
{
var=num[i];
num[i]=num[j];
num[j]=var;
}
}
}
What does the above code do?

Answers:

  1. It prints the elements of the array in the ascending orde
  2. It calculates the sum of the elements of the array
  3. It sorts the array in the ascending orde
  4. It sorts the array in the descending orde
  5. It calculates the average of the elements of the array

26. Read the following two declaration statements.

1. #include <stdio.h>

2. #include “stdio.h”

Which of the following statements pertaining to the above two statements are correct?

Answers:

  1. For statement 1, the header file will be searched first in the local directory and then in the standard system directories such as “/usr/include”
  2. For statement 1, the header file will be searched in the standard system directories such as “/usr/include”
  3. For statement 2, the header file will be searched first in the local directory and then in the standard system directories such as “/usr/include”
  4. For statement 2, the header file will be searched in the standard system directories such as “/usr/include”
  5. None of the above

27. Is the following statement correct? If not, why not? If yes, what is the size of the array?

int array[][3] = { {1,2}, {2,3}, {3,4,2} };

Answers:

  1. Yes, the size is three columns by two rows
  2. Yes, the size is two columns by two rows
  3. No, the first dimension is omitted
  4. No, one of the three initializer sets contains too many numbers
  5. Yes, the size is three columns by three rows

28. What would be printed on the standard output as a result of the following code snippet?

#define max(a, b) ((a) > (b)?(a):(b))
main()
{
int a=4;
float b=4.5;
printf(“%.2fn”,max(a, b));
}

Answers:

  1. Results in Compilation Error
  2. Undefined value
  3. 4.50
  4. 4.0
  5. None of the above

29. What will be the output of the following program?
#include <assert.h>

main()

{

int n = 5;

assert(n > 3); //statement 1

n = n+2;

assert(n > 7);//statement 2

return 0;

}

Answers:

  1. Assertion ‘n > 3’ failed; Program aborts at statement 1
  2. Assertion ‘n > 7’ failed; Program aborts at statement 2
  3. Program returns 0 with the value of n as 7
  4. Compilation Error

30. What would be printed on the standard output as a result of the following code snippet?
main()

{

enum {red, green, blue = 6, white};

printf(“%d %d %d %d”, red, green, blue, white);

return 0;

}

Answers:

  1. 0 1 6 2
  2. 0 1 6 7
  3. Will result in Compilation Error
  4. None of the above

31. Which file header is to be included for file handling in a C program?

Answers:

  1. string.h
  2. file.h
  3. stdio.h
  4. stdlib.h
  5. ctype.h

32. What will be printed on the standard output as a result of the following code snippet?
void main()
{
char arr[] = {‘R’,’A’,’M’};
printf(“%d”,strlen(arr));
}

Answers:

  1. 1
  2. 3
  3. 4
  4. Cannot be determined

33. Which function will you use to write a formatted output to the file?

Answers:

  1. fputc()
  2. fputs()
  3. fprintf()
  4. fseek()
  5. ftell()

34. Which function returns the current pointer position within a file?

Answers:

  1. ftell()
  2. fseek()
  3. fgetc()
  4. fread()
  5. fscanf()

35. Which of the following is not a string function?

Answers:

  1. strlen()
  2. strcmp()
  3. strcpy()
  4. strrev()
  5. strcomp()

36. Which of the following declarations of structures is/are valid?

1)
struct node {
int count;
char *word;
struct node next;
}Node;
2)
struct node {
int count;
char *word;
struct node *next;
}Node;
3)
struct node {
int count;
char *word;
union u1 {
int n1;
float f1;
}U;
}Node;

Answers:

  1. 123
  2. 12
  3. 23
  4. 2
  5. None of the above

37. What would be printed on the standard output as a result of the following code snippet?
main()

{

int arr[10];

int a = sizeof(arr);

printf(“%dn”,a);

return 0;

}

Answers:

  1. Compilation Error
  2. 10
  3. 4
  4. 40

38. Which of the following is a function for formatting data in memory?

Answers:

  1. sprintf()
  2. printf()
  3. scanf()
  4. free()
  5. atol()

39. Which function allocates memory and initializes elements to 0?

Answers:

  1. assign()
  2. calloc()
  3. malloc()
  4. swab()
  5. allocate()

40. What will be printed on the standard output as a result of the following code snippet?

void main()
{
int i,j,k;
i=4;
j=30;
k=0;
k=j++/i++;
++k;
printf(“%d %d %d”,i,j,k);
}

Answers:

  1. 5 31 8
  2. 5 31 7
  3. 5 31 6
  4. 4 30 7

41. Given the operators:
1) *

2) /

3) %
What would be the order of precedence?

Answers:

  1. 1,2,3
  2. 1,3,2
  3. 3,2,1
  4. All have the same precedence
  5. 1 and 2 have the same precedence, 3 is of lower precedence

42. Which of the following sets of conversion statements may result in the loss of data?

Answers:

  1. int i; char c; i=c; c=i;
  2. int i; char c; c=i; i=c;
  3. int i; float f; i=f; f=i;
  4. None of the above

43. Which of the following standard functions is used to close a file?

Answers:

  1. fileclose()
  2. closefile()
  3. fclose()
  4. Any of the above

1,988 total views, 6 views today