Professional Documents
Culture Documents
5 Which of the following keys on the keyboard is used to erase the character to
the left of the cursor position?
6 You want to capture information from books and store it on your computer as
an image. Which of the following devices enables you to perform the required
task?
7 You want to buy a device that would allow you to record sound. Which of the
following devices would allow you to perform the required task?
8 You have brought a new sound card. Now, you want to attach the sound card
to your system in order to use it. Which of the following components of the
computer can be attached to the sound card?
9 You have recorded some videos of your friend's party. Now, you want to store
the videos on a high capacity storage device on your computer.
You do not want to move the storage device between computers. Which of the
following storage devices would you use to perform the required task?
10 You want to store information regarding the employees of your organization in
a computer file. You want to store the information in the form of records where
the details about each employee are contained in a single line. Which of the
following types of computer file would enable you to perform the required task?
11 You have copied a large number of image files to your computer. You want to
change the view of the contents pane so that the size of a image is displayed
along with the image name. How will you perform the required task?
12 You are viewing the contents of the D:\Computer folder in Windows Explorer.
You, then moved to view the E:\Windows folder. Now, you want to navigate to
the D:\Computer folder again. Which of the following buttons in the explorer
toolbar would enable you to perform the preceding task?
13 You have created a file named MyFile under the D: drive of your computer.
Now, you want to copy MyFile to another folder named Projects that is created
under the D: drive. Identify the correct sequence of steps required to copy
MyFile to the Projects folder.
14 You are using Windows XP and want to change the appearance of the desktop
screen. Which of the following options states the correct steps to change the
appearance of the desktop?
15 You are viewing a text file using Notepad. While viewing the file, you want to
search for a particular word in the file. Which of the following options states the
correct sequence to find the required word in the file?
34 Which of the following tools of the Formula Auditing toolbar in Excel can be
used to determine the cells that are dependent on a specified cell?
35 Which of the following task panes of PowerPoint can be used to determine the
type and size of bullet points in the presentation?
36 Which of the following features of PowerPoint can be used to determine the
number of slides that would be printed on a single page of the handout?
37 Which of the following features of Microsoft Word can be used to send a letter
to a group of people with the same content?
38 You are creating a document in word. You want to control the AutoCorrect
entry by undoing the AutoCorrect change. Which of the following productivity
enhancing tools can you use to accomplish the required task?
39 You are creating a document for your organization. To enhance the
appearance of the document, you decide to add the logo of your organization
such that it is displayed as a background in the document. Which of the
following features of Word 2002 would you use to perform the required task?
43 You are creating a word document. Whenever you type the word "acme", it is
automatically changed to Acme Inc. by the AutoCorrect feature. You want to
stop the word from being changed automatically. Which of the following options
states the correct steps to perform the required task?
44 You have added a table to your document. You want to change the style of the
table to one of the predefined styles available in Word. Which of the following
options states the correct sequence of steps to perform the required task?
45 You are creating a document in Word. You want to add a watermark to your
document. You need to use an image stored on your computer for the
watermark. Which of the following options states the correct sequence of steps
to add a watermark to the document?
61 Kim has created an organizational chart of her organization. Now, she needs to
create a high quality visual of the organizational chart on paper. How can Kim
accomplish the required task?
62 You have bought a new monitor. The monitor supports a resolution of 1024 x
768 with 256 colors. You find out that the graphics adaptor of your computer
does not support the resolution of the monitor. How would you ensure that the
graphics adaptor supports the appropriate resolution?
63 Tim has to create a project on the solar system for his school. He decides to
use the Internet to search for the information on Mars, Saturn, and Jupiter. He
wants to search for the websites or Web pages that contain the information
about all the planets specified in the search query. How should Tim phrase the
search query to get the desired result?
64 Jim needs to transfer some files from his computer to his friend's computer.
The total size of the files is 2 GB. How can he transfer the files between the
two computers?
65 You have to create an application for a TV store. The application calculates the
discount amount that is provided when a customer buys a TV. The amount of
discount that is provided depends on the type and the screen size of the TV.
You create a flowchart for your program where B represents a Black and White
TV, and C represents a Color TV.
Click the Exhibit button to view the flowchart.
What would be the amount of discount provided if a customer buys a Color TV
with a 21 inch screen?
using System;
class Car
{
public string Color;
public void Honk()
{
Console.WriteLine("BEEP BEEP!" );
}
}
class Result
{
static void Main(string[] args)
{
Car Ford = new Car(); ;
Ford.Honk();
Console.ReadLine();
}
}
using System;
public class FunctionCount
{
public static int count = 0;
public static void CountFunction()
{
count++;
System.Console.WriteLine("Count function is Called by Main {0}
times.", count);
}
public static void Main(string[] args)
{
for (int var = 0; var < 10; var++)
{
FunctionCount.CountFunction();
}
Console.ReadLine();
}
}
How many times would the CountFunction method be called?
70 You are creating a calculator application by using the following code:
using System;
namespace Calculator
{
class Calculator
{
public int number1, number2;
public Calculator(int num1, int num2)
{
number1 = num1;
number2 = num2;
}
public static Calculator operator -(Calculator c1)
{
c1.number1 = -c1.number1;
c1.number2 = -c1.number2;
return c1;
}
public void Print()
{
Console.WriteLine(" number1=" + number1);
Console.WriteLine(" number2=" + number2);
Console.ReadLine();
}
}
class EntryPoint
{
static void Main()
{
Calculator calc = new Calculator(15, -25);
calc.Print();
}
}
}
71 Predict the output of the following code:
using System;
namespace ConsoleApplication1
{
struct NumberCount
{
public int i;
public NumberCount(int initval)
{
this.i = initval;
}
public static NumberCount operator ++(NumberCount arg)
{
arg.i++;
return arg;
}
}
class TestClass
{
static void Main(string[] args)
{
NumberCount Count1 = new NumberCount(1);
NumberCount Count2 = Count1++;
Console.WriteLine(Count1.i);
Console.WriteLine(Count2.i);
Count2 = ++Count1;
Console.WriteLine(Count1.i);
Console.WriteLine(Count2.i);
Console.ReadLine();
}
}
}
72 Consider the following code snippet:
class CalculateMax
{
public int Max(int number1, int number2)
{
if (number1 > number2)
{
return number1;
}
else
{
return number2;
}
}
public float Max(float number1, float number2)
{
if (number1 > number2)
{
return number1;
}
else
{
return number2;
}
}
}
Analyze the preceding code and identify the approach used to implement
polymorphism.
73 Jim has to develop an application for his college. While creating the
application, he decides to re-use some methods of an existing class B1 in a
new
class, Derived. He writes the following code:
using System;
public class B1
{
public void Function1()
{
Console.WriteLine("Base class");
}
}
class Derived : B1
{
void Function1();
using System;
abstract class Animal
{
public abstract void FoodHabits()
{
}
}
class Carnivorous: Animal
{
public override void FoodHabits( )
{
Console.WriteLine("The Carnivorous animals eat only meat");
}
}
class Herbivorous: Animal
{
public override void FoodHabits( )
{
Console.WriteLine("The Carnivorous animals eat only plants");
}
}
What is the source of error in the preceding code?
75 Tim is developing an application using C#. He has to create a class named Car
containing a method named Engine. The engine method has a statement that
displays a message to the user. Tim wants to override the Engine method in a
class named Truck that is derived from the Car class. Tim has written the
following code to perform the required task:
using System;
class Car
{
using System;
namespace Test
{
sealed class myClass
{
void display()
{
Console.WriteLine("Hello");
}
}
class disp : myClass
{
void abcd()
{
Console.WriteLine("Wassup");
}
static void Main()
{
disp obj = new disp();
obj.abcd();
Console.Read();
}
}
}
The preceding code gives error when it is compiled. Analyze the code and
identify the line of code causing the error.
77 Lim is creating an application using C#. He has created an interface named
IOrderdetails that has two methods, UpdateCustStatus() and TakeOrder(). The
interface is implemented by a class named ItemsDetails. Lim has written the
following code snippet:
However, the code doesn't compile and gives a compile-time error. Identify the
reason for the error.
using System;
class Calculator
{
static int number1, number2, total;
Calculator(int num1, int num2)
{
number1 = num1;
number2 = num2;
}
public void CalculateNumber()
{
total = number1 + number2;
}
public void DisplayNumber()
{
Console.WriteLine("The total is : {0}", total);
}
public static void Main(string[] args)
{
int var1, var2;
Console.WriteLine("Enter Value 1 :");
var1=Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter Value 2 :");
var2 = Convert.ToInt16(Console.ReadLine());
Calculator C1 = new Calculator(var1,var2);
C1.CalculateNumber();
C1.DisplayNumber();
Console.ReadLine();
}
}
Analyze the preceding code and identify the correct output, if the value of var1
and var 2 is 50 and 70 respectively.
80 Consider the following code:
using System;
class Calculator
{
static int number1=20;
static int number2=30;
static int total=0;
81 Jim is creating an application for his college project. The application has a
class named myConnection with a method named dbCon() that uses a
database connection. Jim wants to add another method to the class to release
the database connection as soon as the dbCon() method completes execution.
How will Jim perform the required task?
82 Predict the output of the following code:
using System;
namespace Objects
{
class TestCalculator
{
TestCalculator()
{
Console.WriteLine("Constructor Invoked");
}
~TestCalculator()
{
Console.WriteLine("Destructor Invoked");
Console.Read();
}
public static void Main(string[] args)
{
Console.WriteLine("Main() Begins");
TestCalculator calc1 = new TestCalculator();
{
Console.WriteLine("Inner Block Begins ");
TestCalculator calc2 = new TestCalculator();
Console.WriteLine("Inner Block Ends");
}
Console.WriteLine("Main() ends");
Console.Read();
}
}
}
class FileHandling
{
void fileAccess()
{
FileStream File1= new FileStream("C:\\Myfile.txt", FileMode.Append,
FileAccess.Write);
}
}
Analyze the preceding code and identify the use of the FileMode.Append
enumerator in the fileAccess() method.
84 Tom has to create an application in C# that would be used to read data from a
string buffer. The application accepts data in the string buffer from the user and
displays it on screen. Which of the following code snippets can he use to
perform the required task?
using System;
using System.IO;
namespace File_Handling
{
class Tester
{
88 John has to create an application that would display the full path of a user-
specified folder, and the date and time on which the folder was last accessed.
Which of the following code snippets should John use to perform the required
task?
89 Tom has to create an application to divide two numbers. The numbers must be
accepted from the user. However, he must ensure that if the user tries to divide
a number by zero, then the application should catch the exception and display
an appropriate error message. Tom has written the following code snippet to
implement the required functionality in his application:
class division
{
void DivideNum()
{
int a;
int b;
int result;
Console.WriteLine("Enter first number");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second number");
b = Convert.ToInt32(Console.ReadLine());
try
{
result = a / b;
Console.WriteLine("The result after dividing the two numbers is: {0}", result);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("e.message");
}
}
However, the preceding code does not handle the exception if the user gives
the value of b as zero. Identify the reason for this.
90 You have to develop an application using C#. The application should have a
feature that enables it to communicate with different processes. Which of the
following predefined classes do you need to use in your application to perform
the required task?
91 Jim is developing a C# application. He has used attributes in the application.
Now, he needs to specify essential information of an attribute, which he has
used in the application. Which of the following options would enable him to
perform the required task?
92 John is developing an application using C#. He wants to use one of the
predefined attributes of .NET that would enable him to call the member
functions of unmanaged code from his application. Which of the following
predefined attributes would allow him to perform the required task?
93 You are developing a C# application. You have defined a custom attribute for
your application. Now, you want to apply the custom attribute to every element
of your application, such as classes and events using a single member of the
AttributeTargets enumerator. Which of the following members of
AttributeTargets enumerator can you use to perform the preceding task?
94 Tim has developed an application that has some custom attributes defined in it.
Now, he wants to access the metadata of the preceding application while it is
running. Which of the following namespaces does Tim need to use to access
the metadata of the running application?
95 You have to create an application that accepts data from the user and saves
the same into a text file named Myfile.txt. Which of the following code snippets
would you use to perform the required task?
96 Consider the following code snippet:
void display()
{
try
{
FileStream fs = new FileStream("orders.txt", FileMode.Open,
FileAccess.Read);
StreamReader sr = new StreamReader(fs);
String str = sr.ReadLine();
Console.WriteLine(str);
Console.Read();
}
catch (IOException e)
{
Console.WriteLine(e.Message);
Console.Read();
}
catch (NullReferenceException e1)
{
Console.WriteLine(e1.Message);
}
catch (InvalidCastException e2)
{
Console.WriteLine(e2.Message);
}
catch (ArgumentNullException e3)
{
Console.WriteLine(e3.Message);
}
}
The preceding code gives an exception that displays the message 'Could not
find file', when it is executed. This exception is handled by one of the catch
blocks in the code. Identify the lines of code that handle the exception.
97 John has to create an application using C# that stores data in a binary file.
There are two variables in the application, an integer variable i, and a double
variable d. The application has to store the values of the i and d in a binary file
named binfile.DAT. The application should always create a new file whenever it
writes data to the file. Identify the correct code snippet that John has to write to
perform the required task.
98 Jim is creating an application using C#. The application has to calculate the
sum of values in an integer array. Jim needs to ensure that the application
displays an exception message if the integer array is assigned any out of range
value. Identify the code snippet that would help Jim to handle the exception.
99 You have created an application for a fast food joint. The workers of the fast
food joint save the order data in a common file named orders.txt. You have
used the following code snippet to save the order data:
void Write()
{
Console.WriteLine("Enter order data");
String str=Console.ReadLine();
FileStream fs = new FileStream("orders.txt", FileMode.Append,
FileAccess.Write, FileShare.None);
StreamWriter sr = new StreamWriter(fs);
String str = "Hello";
sr.Write(str);
sr.Flush();
sr.Close();
fs.Close();
}
However, the preceding code gives a compile-time error. Identify the line(s) of
code causing the error.
100 Predict the output of the following code snippet:
101 Which of the following I/O devices transforms the image to ASCII codes that is
used by a computer to represent the characters you find on your keyboard,
such as alphabets, numbers, punctuation marks, and graphics?
102 Which of the following types of touch screens send sound waves across the
computer screen to look for interruptions caused by touch?
103 Which of the following types of computer mouses allows to work from the
distance upto one and a half meters away from the computer?
104 Which of the following components of a motherboard provides the timing signal
in the form of electronic pulses that are used by the computer components to
set up a working pace?
105 Which of the following types of Web browsers allows its users to customize font
sizes and colors, zoom images, remove scroll bars, and enable sound alerts?
106 You want to use a Web browser that occupies very little hard disk space and
provides rapid access to the Internet. In addition, it can be used by physically
challenged individuals. Which of the following Web browsers meets your
requirements?
107 John wants to attach a hard disk to the computer. For this, he wants to use a
port that sends a byte of data bit by bit. Which of the following ports can help
John to achieve the required task?
108 You want to use search engine for the Web pages that contain the exact
phrase, Life beyond Earth. Which of the following operators will you use in the
search phrase to find such Web pages?
109 You have recently explored Internet and found the latest information on the
subjects for which you are pursuing professional certifications. Therefore, you
want to bookmark those Web pages. Which of the following options allows you
to perform the required task?
110 Which of the following options is NOT a software component required to
connect a computer to the Internet?
111 While assembling a computer system, Sam wants to use a bus that can
operate between the expansion bus and the system bus. Which of the following
types of buses he can use for the same?
112 You are setting up a computer system at your home. You need to attach a
component to the computer system that supplies required voltage to internal
and external components like motherboard and keyboard. Which of the
following components of the system unit will you use to achieve the same?
113 You want to connect your digital camera to your computer system without using
data cables. You want to use a low cost wireless technology that is able to
connect the camera with the computer system within the range of 30 feet.
Which of the following technologies can help you to achieve the same?
114 You want to upgrade your computer system and increase its RAM for faster
data transfer. Which of the following types of RAM will you purchase that can
synchronize memory access with the CPU clock for faster data transfer?
115 You are a regular traveler. You want to purchase a portable computer that is
not bulky and allows basic functionalities, such as I/O operations on data. In
addition, it can contain at least one database with names and address book,
and to-do lists. Which of the following portable devices will you purchase?
"Bat"
Payment
10
"Peter"
Marks
121 Consider the following statements:
Statement A: The % operator returns the remainder value when one number is
divided by another number.
Statement B: Logical operators are used to combine expressions containing
arithmetic operators.
122 You want to compare two numbers and if the numbers are not equal, the
expression should evaluate to true. Which of the following relational operators
will you use for this task?
123 Complete the following expression with an appropriate logical operator so that
it evaluates to true even if one of the individual conditions evaluate to true:
nNum1 = 7 _____ nNum2 > 5
124 Your manager has asked you to book air-tickets for him. Therefore, you
checked the flight requirements and now want to enter the manager's personal
details, such as name, address, and phone number. In which phase of the I-P-
O cycle will you perform the activity of entering the manager details?
125 You have been asked to prepare a descriptive flowchart for generating the
fibonacci series. Which of the following symbols will you use to add comments
to your flowchart?
126 Analyze the given flowchart where a number is accepted and incremented by
1. Identify the incorrect usage of symbol(s), if any, in the flowchart. Click the
Exhibit button to view the flowchart.
128 How many bytes are occupied by the char data type in C# programming
language?
129 Consider X=5. Determine the values of X and Y after the execution of the
following expression:
Y=X++;
130 Which of the following operators is used when you want to compare two values
and perform an action on the basis of the result of that comparison?
136 You have to accept numeric values from the user in a C# program. Which of
the following code snippets can help you to achieve the required task?
Identify the line of code that a C# compiler first looks for in the preceding code
to compile it.
138 You have declared a variable named x and initialized it with the value 20. In
addition, you have declared a boolean variable named Result. Which of the
following code snippets would you use to store the value, true in the Result
variable when the value of x is not equal to 10?
139 Danny wants to use a looping construct in which the body of the loop is
executed at least once and the condition is evaluated for subsequent iterations.
Which of the following looping constructs will Danny use to achieve the
required task?
140 Determine the output of the following code snippet:
int var= 1;
for (; var <= 2; var++)
{
Console.WriteLine ("Value of variable is: {0}", var);
}
141 You have been asked to create a marks-list for the school students using
arrays in the C# language. However, you are not sure about the number of
students in the school. Identify which of the following concepts can be used to
handle an array list of unknown numbers?
142 Consider X=20 and Y=20. Determine the values of X and Y from the following
arithmetic expressions:
X+=Y;
X-=Y;
X*=Y;
X/=Y;
X%=Y;
143 From the following steps of instructions, identify the correct sequence of steps
for the execution of a for loop.
144 You have been asked to maintain bill details of an employee in a single
variable. Which of the following programs will you use for the same?
145 Predict the output of the following code:
using System;
namespace EnumDays
{
class EnumTest
{
enum Days { Sat, Sun, Mon, Tue, Wed, Thu, Fri};
static void Main (string[] args)
{
int First_Day = (int)Days.Sat;
int Last_Day = (int)Days.Fri;
Console.WriteLine("Sat = {0}", First_Day);
Console.WriteLine("Fri = {0}", Last_Day);
Console.ReadLine();
}
}
}
146 You want to create a multidimensional array that calculates the sum of the
array elements. For this, you have declared a multidimensional array by using
the following code snippet:
int sum=0;
int rowSum;
int[,] mArray = new int[2, 4]{
{2,2,2,2},
{3,3,3,3},
};
Identify the correct code snippet that will help you to calculate the sum of
elements of mArray array.
147 You have been asked to write a C# program to check whether the year entered
by the user is a Leap year. For this, you have written the following code:
using System;
class LeapYear
{
static void Main(string[] args)
{
int Year;
Console.WriteLine("Enter the year: ");
Year = Convert.ToInt32(Console.ReadLine());
The preceding code results in an error. Identify the statement(s) that can
generate an error.
148 You have written the following code by using the switch
case construct:
int var;
var = 500;
switch(&&var)
{
case 100:
Console.WriteLine("Century");
break;
case 200:
Console.WriteLine("Double Century");
break;
case 300:
Console.WriteLine("Triple Century");
break;
default:
Console.WriteLine("Invalid value");
break;
Analyze the preceding code and identify the statement(s) that can produce an
error on compilation.
149 You have written the following code to accept five numbers and print the sum
of all the positive numbers entered by the user:
using System;
class BreakContinue
{
static void Main(string[] args)
{
int incr, SumNum, number;
for (SumNum = number = incr = 0; incr < 5; incr += 1)
{
Console.WriteLine("Enter a positive number");
number = (Console.ReadLine());
if (number <= 0)
continue;
SumNum = SumNum + number;
}
Console.WriteLine("The sum of positive numbers entered is {0}",
SumNum);
Console.ReadLine();
}
}
Analyze the preceding code and identify the statement(s) that can produce an
error on compilation.
150 You have written the following program that checks a palindrome character
array:
using System;
namespace ManipulateArray
{
class Palindrome
{
static void Main(string[] args)
{
char[] Str = new char[10];
Console.WriteLine("Enter a Palindrome string (Max 10 Char):");
Str = Console.ReadLine().ToCharArray();
Console.WriteLine(CheckPalindrome(Str));
Console.ReadLine();
}
private static bool CheckPalindrome(char[] myString)
{
int startChar;
int lastChar;
startChar = 0;
lastChar = myString.Length - 1;
while (startChar < lastChar)
{
if (myString[startChar] = myString[lastChar])
{
startChar++;
lastChar--;
}
else
{
return false;
}
}
return true;
}
151 You have written the following C# code that generates the Fibonacci series
upto 200:
using System;
class Fibonacci
{
static void Main(string[] args)
{
int number1;
int number2;
number1=number2=1;
Console.WriteLine("{0}", number1);
while (number2 <= 200)
{
Console.WriteLine(number2);
number2 += number1;
num1 = number2-number1;
}
Console.ReadLine();
}
}
However, the preceding code when compiled generates an error. Identify the
incorrect statement that generates the error in the preceding code.
class calc
{
public int AddNumber(int num1, int num2)
{
int result;
result = num1 + num2;
return result;
}
}
Identify the correct code snippet for calling the AddNumber() method.
164 You want to declare a variable named Mark in the Student class to store some
value. In addition, you want that only one copy of the Mark variable should
exist for the Student class. Which of the following keywords can help you to
declare such a variable?
165 You want to overload the + operator in a C# program. Which of the following
options is the correct syntax to define the function for overloading the +
operator?
166 Sam wants to declare an interface named IOrderDetails, which contains two
methods, UpdateCustStatus() and TakeOrder(). Identify the correct code
snippet that can help Sam to achieve the required task.
177 You are working with a C# application. You have come across with a
requirement where the variables need to be initialized with user supplied values
as soon as the object of the class is created. Which of the following
mechanisms will you use in such a situation?
178 Consider the following statements:
Statement A: The dispose() method is called after the last reference to an
object is released from the memory.
Statement B: Constructors are special methods that are used to release the
instance of a class from memory.
On the basis of the preceding statements, identify which of the following
statements is correct?
179 You are creating a C# application for your organization. You want that the
application should be able to dynamically change the reference to the methods
in a class. Which of the following concepts will you use in your application to
perform this task?
180 Which of the following tasks is NOT performed by the publisher object while
defining a delegate for an event?
181 You want to declare a delegate in you C# program. The delegate should be
used to refer any method that takes an integer parameter and does not return
any value. Which of the following code snippets can be used to declare such a
delegate?
182 Which of the following statements is NOT true about delegates?
183 You have been assigned the following tasks for implementing events with
delegates in a C# program:
1) Declare a delegate
2) Declare an event based on the delegate
3) Fire the event
Which of the following objects will you use to accomplish the preceding tasks?
184 You have defined an event and a delegate by using the following code snippet:
Further, you have created a class named Student that contains a method
named Wakeup(). You want that the WakeUp() method should be called at 6
am. Identify the correct code snippet that allows the Student class to subscribe
to the event named TimeToRise.
189 Which of the following definitions correctly defines the Flush method of
StreamWriter class?
using System;
namespace ThreadExample
{
class MainThreadExample
{
public static void Main(string[] args)
{
Thread Th = Thread.CurrentThread;
Th.Name = "MainThread";
Console.WriteLine("The current thread after name change: {0}",
Th.Name);
Console.ReadLine();
}
}
}
191 Consider the following code:
using System;
using System.Threading;
namespace ThreadSample
{
class BasicThreadApp
{
public static void ChildThreadCall()
{
Console.WriteLine("Child thread started");
int SleepTime = 5000;
Console.WriteLine("Sleeping for {0} seconds", SleepTime/1000);
ChildThread.Sleep(SleepTime);
Console.WriteLine("Waking Up");
}
public static void Main()
{
ThreadStart ChildRef = new ThreadStart(ChildThreadCall);
Console.WriteLine("Main - Creating Child thread");
Thread ChildThread = new Thread(ChildRef);
ChildThread.Start();
Console.WriteLine("Main - Have requested the start of child
thread");
Console.ReadLine();
}
}
}
The preceding code generates a compile-time error. Identify the line of code
that will generate the error.
192 Sam has created the following method in a C# application to accept and print
book details:
Further Sam wants to call this method by using thread in the application.
Identify the correct code snippet that Sam should implement to create a thread
and call the BookDetails() method by using the newly created thread.
193 Jonathan has developed a notepad application by using C#. In the application,
he has created three methods namely, Write(), Save(), and Print() to write data
in a text file, save the file, and print the file, respectively. He wants to call these
methods by using threads. Further, he wants that the Save() method should be
called after the execution of the Write() method and the Print() method should
be called after the file has been saved. Which of the following code snippets
can help Jonathan to accomplish the preceding tasks?
194 Stella wants to create a clock application in C#. After every five seconds, the
application displays a message to the user that 5 seconds are over. This
should continue till one minute is over. Which of the following codes can help
Stella to implement the required task?
195 Mr. Beth has been assigned a task to create a game application in C# that
gives a user 15 seconds to type the text printed on the screen. He writes the
following code for the game:
using System;
using System.IO;
using System.Threading;
namespace Game
{
public class Typometer
{
public void StartGame()
{
String str = "The Cheater Cheats the Cheating Code";
Console.WriteLine(str);
String userVal = Console.ReadLine();
if (userVal == str)
{
Console.WriteLine("\nYou WON! Game Over! \n");
}
else
{
Console.WriteLine("\nThe strings does not match..Game Over!
\n");
}
Thread.Sleep(15000);
}
}
class Game
{
static void Main(string[] args)
{
Console.WriteLine("You have to complete the game within 15
seconds\n");
Typometer obj = new Typometer();
using System;
using System.Threading;
class ThreadSchedule
{
public static void Doctor()
{
for (int Cnt = 0; Cnt < 2; Cnt++)
{
Console.Write("\nDoctor: Give medicine " + (Cnt + 1));
Console.WriteLine();
Thread.Sleep(1000);
}
Console.WriteLine("Doctor: Work finished");
}
public static void Nurse()
{
for (int Cnt = 0; Cnt < 2; Cnt++)
{
Console.Write("Nurse: Medicine " + (Cnt + 1) + " given\n");
Console.WriteLine();
Thread.Sleep(1000);
}
Console.WriteLine("Nurse: Work finished");
}
using System;
using System.Threading;
namespace ThreadExample
{
class FileAccess
{
public void WriteData(string Data)
{
Monitor.Enter(this);
Console.WriteLine("Writing data to file");
for (int Cnt = 0; Cnt < 5; Cnt++)
{
Console.WriteLine("Writing in Line {0}", Cnt );
}
Monitor.Exit();
}
}
class ThreadMonitorClass
{
public static FileAccess Fd = new FileAccess();
public static void ChildThread1()
{
Console.WriteLine("Thread 1 started");
Fd.WriteData("T1");
}
public static void ChildThread2()
{
Console.WriteLine("Thread 2 started");
Fd.WriteData("T2");
}
public static void Main()
{
ThreadStart Child1 = new ThreadStart(ChildThread1);
ThreadStart Child2 = new ThreadStart(ChildThread2);
Thread Thread1 = new Thread(Child1);
198 Consider the following code that locks the code of the UpdateAC() method by
using the lock statement:
using System;
using System.Threading;
namespace ThreadExample
{
class FileAccess
{
public void UpdateAC(string Data)
{
lock()
{
Console.WriteLine("Updating Salary Accounts: {0}", Data);
for (int Cnt = 0; Cnt < 5; Cnt++)
{
Console.WriteLine("Updated {0} record", Cnt+1);
}
}
}
}
class ThreadMonitorClass
{
public static FileAccess Fd = new FileAccess();
public static void ChildThread1()
{
Console.WriteLine("Thread 1 started");
Fd.UpdateAC("T1");
}
public static void ChildThread2()
{
Console.WriteLine("Thread 2 started");
Fd.UpdateAC("T2");
}
public static void Main()
{
ThreadStart Child1 = new ThreadStart(ChildThread1);
199 Sim hasThreadStart Child2
been assigned the=task
newofThreadStart(ChildThread2);
creating a C# application for a game. She
has to use the Thread class to perform different functions in the game.
Therefore, she created an instance of the Thread class in the application. Now,
she has to allocate system resources such as memory to the instance of the
Thread class. How will she perform the required task?
200 Jim has to create an application that accepts two numbers from the user and
displays the remainder after dividing the two numbers. He wants to implement
exception handling in his application. He wants to handle the exception in such
a way that application displays the message Calculation complete
irrespective of any exception. Which of the following code snippets will help Jim
to perform the required task?
1, First generation 2, Second generation 3, Third generation 4, Fourth generation 3
1, 1. Click the right 2, 1. Click the right 3, 1. Select the 4, 1. Click the right 1
mouse button on the mouse button on the Appearance tab in the mouse button on the
blank area of the blank area of the Display Properties blank area of the
Desktop screen. Desktop screen. dialog box. Desktop screen.
2. Select the 2. Select the 2. Click the right 2. Select the
Properties option Appearance tab in the mouse button on the Properties option
from the menu. Display Properties blank area of the from the menu.
3. Select the dialog box. Desktop screen. 3. Select the
Appearance tab in 3. Select the 3. Select the Appearance tab in
the Display Properties Properties option from Properties option from the Display Properties
dialog box. the menu. the menu. dialog box.
4. Select the 4. Select the 4. Select the 4. Click the OK button
appropriate option appropriate option appropriate option to apply the changes.
from the Windows from the Windows and from the Windows and 5. Select the
and buttons drop- buttons drop-down list buttons drop-down list appropriate option
down list box. box. box. from the Windows
5. Click the OK button 5. Click the OK button 5. Click the OK button and buttons drop-
to apply the changes. to apply the changes. to apply the changes. down list box.
1, 1. Select the Find 2, 1. Click the Edit 3, 1. Select the Find 4, 1. Click the Edit 2
option menu option menu.
2. Click the Edit menu 2. Select the Find 2. Enter the required 2. Enter the required
3. Enter the required option word in the Find what word in the Find what
word in the Find what 3. Enter the required text box in the Find text box in the Find
text box in the Find word in the Find what dialog box. dialog box.
dialog box. text box in the Find 3. Click the Edit menu 3. Select the Find
4. Click the Find Next dialog box. 4. Click the Find Next option
button to find the 4. Click the Find Next button to find the 4. Click the Find Next
required word. button to find the required word. button to find the
required word. required word.
1, 0 2, 10 3, 30 4, 40 1
1, 1. Select the New 2, 1. Click the Create 3,1. Select the New 4, 1. Select the New 3
Photo Album button. Photo Album Photo Album
command from the 2. Select the New command from the command from the
Insert menu. Photo Album Insert menu. Insert menu.
2. Click the command from the 2. Click the File/Disk 2. Click the Create
Scanner/Camera Insert menu. button. button.
button. 3. Click the 3. Select the pictures 3. Click the File/Disk
3. Select the pictures Scanner/Camera that need to be button.
that need to be button. inserted and click the 4. Select the pictures
inserted and click the 4. Select the pictures Insert button. that need to be
Insert button. that need to be 4. Click the Create inserted and click the
4. Click the Create inserted and click the button. Insert button.
button. Insert button.
1, 1. Select the Sum 2, 1. Click in a cell, 3, 1. Click in a cell, 4, 1. Select the Sum 2
command. and then click the and then click the command.
2. Click in a cell, and down arrow of the down arrow of the 2. Select the range of
then click the down AutoSum button in the AutoSum button in the cells that need to be
arrow of the AutoSum standard toolbar. standard toolbar. added.
button in the standard 2. Select the Sum 2. Select the Sum 3. Click in a cell, and
toolbar. command. command. then click the down
3. Select the range of 3. Select the range of 3. Press the Enter arrow of the AutoSum
cells that need to be cells that need to be button. button in the standard
added. added. 4. Select the range of toolbar.
4. Press the Enter 4. Press the Enter cells that need to be 4. Press the Enter
button. button. added. button.
1, \a 2, \b 3, \\ 4, \0 2
1, 8% 2, 10% 3, 5% 4, 14% 2
1, 0 2, 5 3, 2 4, 4 1
1, The code would 2, Beep Beep! 3, The code would not 4, BEEP BEEP! 4
give a runtime error compile
1, Opens the file 2, Opens the file 3, Opens the file 4, Deletes the 3
Myfile.txt and the Myfile.txt and MyFile.txt and places existing file Myfile.txt
places the cursor at truncates the file, so the cursor at the end and creates a new file
the beginning of the that its size is zero of the file. with the same name.
file. bytes.
1,string 2, string 3, string 4, string 4
str=Console.ReadLin str=Console.ReadLine str=Console.ReadLine str=Console.ReadLin
e(); (); (); e();
StringWriter sr FileStream sr StreamReader StringReader
= new = new FileStream(str); sr = new sr = new
StringWriter(str); StringReader(str); StringReader(str);
Console.WriteLine(sr.
Console.WriteLine(sr. ReadLine()); Console.WriteLine(sr. Console.WriteLine(sr.
ReadLine()); ReadLine()); ReadLine());
Console.Read();
Console.Read(); Console.Read(); Console.Read();
1, 1. Opens the file 2, 1. Opens the file 3, 1. Opens the file 4, 1. Opens the file 1
Myfile.txt, and Myfile.txt, and Myfile.txt, and Myfile.txt, and
prepares the stream prepares the stream prepares the stream prepares the stream
for a read operation. for a read operation. for a read operation. for a read operation.
2. Positions the file 2. Positions the file 2. Positions the file 2. Positions the file
pointer at the pointer at the end of pointer at the current pointer at the
beginning of the the stream. position within the beginning of the
stream. 3. Reads a line of stream. stream.
3. Reads a line of characters from the 3. Reads data types 3. Converts
characters from the current stream and from a binary stream. characters into binary
current stream and returns data as a data types and reads
returns data as a string. the data types from
string. the binary stream.
1, The code would list 2, The code would 3, The code would list 4, The code would list 3
the name and size of result in an error. the name and size of the name and the
all the sub folders all the files under the total size of the
under the c:\Windows c:\Windows folder. c:\Windows folder.
folder.
1, StreamReader sr = 2, 3, FileStream fs = 4, sr.Close(); 2
new sr.BaseStream.Seek( new
StreamReader(fs); 0, SeekOrigin.End); FileStream("Myfile.txt"
,
FileMode.Open,FileAc
cess.Read);
1, 2, System.AppDomain 3, System.Attribute 4, 2
System.AsyncCallbac System.AttributeTarg
k ets
1, != 2, < 3, = 4, > 1
1, The while loop 2, The for loop 3, The do while loop 4, The foreach loop 3
1, Value of variable 2, Value of variable is: 3, The compiler will 4, Value of variable 2
is: 0 1 generate a syntax is: 0
Value of variable is: 1 Value of variable is: 2 error. Value of variable is: 1
Value of variable is: 2
1, By using param 2, By using foreach 3, By using IndexOf 4, By using Rank 1
arrays statement method property
1, X=0 and Y=20 2, X=20 and Y=20 3, X=0 and Y=0 4, X=20 and Y=0 1
1, for (int row=0; row 2, for (int row=0; row 3, for (int row=0; row 4, for (int row=0; row 1
< 2; row++) <col; row++) < 2; row++) < 2; row++)
{ { { {
rowSum = rowSum = rowSum = rowSum =
0; 0; 0; 0;
for (int for (int for (int for (int
col=0; col < 4; col++) col=0; col < 4; col++) col=0; col < 3; col++) col=0; col < row; col+
{ { { +)
{
Console.Write("{0}\t", Console.Write("{0}\t", Console.Write("{0}\t",
mArray[row,col]); mArray[row,col]); mArray[row,col]); Console.Write("{0}\t",
mArray[row,col]);
rowSum=rowSum+m rowSum=rowSum+mA rowSum=rowSum+m
Array[row, col]; rray[row, col]; Array[row, col]; rowSum=rowSum+m
Array[row, col];
} } }
sum = sum sum = sum sum = sum }
+ rowSum; + rowSum; + rowSum; sum = sum
+ rowSum;
Console.Write(" = Console.Write(" = {0}", Console.Write(" = {0}",
{0}", rowSum); rowSum); rowSum); Console.Write(" =
{0}", rowSum);
Console.WriteLine(); Console.WriteLine(); Console.WriteLine();
Console.WriteLine();
} } }
}
Console.WriteLine("T Console.WriteLine("Th Console.WriteLine("T
he sum of the array e sum of the array is: he sum of the array is: Console.WriteLine("T
is:{0}", sum); {0}", sum); {0}", sum); he sum of the array
is:{0}", sum);
1, if ((Year % 4 == 2, Year = 3, 4, static void 1
0) ; (Year / 100 != 0 || Convert.ToInt32(Cons Console.WriteLine("E Main(string[] args)
Year % 400 == 0)) ole.ReadLine()); nter the year: ");
1, int var; 2, case 100: 3, default: 4, switch(&&var) 4
var = 500;
Console.WriteLine("C Console.WriteLine("In
entury"); valid value");
break; break;
1, The public access 2, The private access 3, The protected 4, The internal access 1
specifier specifier access specifier specifier
1, +=, -=, *= 2, *, /, % 3, +, - 4, ! , ~, ++ 1
1, Instantiation 2, Utilization 3, Inheritance 4, Composition 4
relationship relationship relationship relationship
1, virtual 2, override 3, void 4, abstract 2
1, public delegate 2, public delegate void 3, public delegate int 4, public delegate int 2
void MyDelegate MyDelegate (int i); MyDelegate (int i); MyDelegate ();
(string s);
1, It will generate the 2, It will generate the 3, It will generate the 4, It will generate the 3
following output: following output: following compile time following output:
The current thread The current thread error: The current thread
after name change: after name change: The name 'Thread' after name change:
MainThread Th.Name does not exist in the {0}, MainThread
current context.
1, Thread 2, ThreadStart 3, ChildThread.Start(); 4, 4
ChildThread = new ChildRef = new ChildThread.Sleep(Sl
Thread(ChildRef); ThreadStart(ChildThre eepTime);
adCall);
1, public static void 2, public static void 3, public static void 4, public static void 1
Main(string[] args) Main(string[] args) Main(string[] args) Main(string[] args)
{ { { {
ThreadStart ThreadStart ThreadStart ThreadStart
ChildRef = new ChildRef = new ChildRef = new ChildRef = new
ThreadStart(BookDet ThreadStart(BookDeta ThreadStart(); ThreadStart();
ails); ils()); Thread Thread
Thread Thread ChildThread = new ChildThread = new
ChildThread = new ChildThread = new Thread(ChildRef); Thread(ChildRef);
Thread(ChildRef); Thread(ChildRef);
ChildThread.Start(); ChildThread.Start();
ChildThread.Start(); ChildThread.Start();
ChildThread.CallMeth ChildThread.BookDet
} } od(BookDetails); ails();
}
}
1, public static void 2, public static void 3, public static void 4, public static void 2
Main() Main() Main() Main()
{ { { {
ThreadStart ThreadStart ThreadStart ThreadStart
ChildW = new ChildW = new ChildW = new ChildW = new
ThreadStart(Write); ThreadStart(Write); ThreadStart(Write); ThreadStart(Write);
ThreadStart ThreadStart ThreadStart ThreadStart
ChildS = new ChildS = new ChildS = new ChildS = new
ThreadStart(Save); ThreadStart(Save); ThreadStart(Save); ThreadStart(Save);
ThreadStart ThreadStart ThreadStart ThreadStart
ChildP = new ChildP = new ChildP = new ChildP = new
ThreadStart(Print); ThreadStart(Print); ThreadStart(Print); ThreadStart(Print);
public static void public static void public static void public static void
Main() Main() Main() Main()
{ { { {
ThreadStart ThreadStart ThreadStart ThreadStart
ChildRef = new ChildRef = new ChildRef = new ChildRef = new
ThreadStart(ChildThr ThreadStart(ChildThre ThreadStart(ChildThre ThreadStart(ChildThr
eadCall); adCall); adCall); eadCall);
1, The 2, The 3, The 4, The 3
Thread.Sleep(15000); Thread.Sleep(15000); Thread.Sleep(15000); Thread.Sleep(15000);
statement is placed at statement is placed at statement is placed at statement is placed at
the wrong position. It the wrong position. It the wrong position. It the wrong position. It
should come after the should come before should come after the should come before
following statement: the following following statement: the following
String userVal = statement: t.Start(); statement:
Console.ReadLine(); Console.WriteLine("\n str = "The Cheater
You WON! Game Cheats the Cheating
Over! \n"); Code";
1, Doctor: Give 2, Doctor: Give 3, Doctor: Give 4, Doctor: Give 4
medicine 1 medicine 1 medicine 1 medicine 1
Doctor: Give Doctor: Give medicine Nurse: Medicine 1 Nurse: Medicine 1
medicine 2 2 given given
Doctor: Work finished
Nurse: Medicine 1 Doctor: Give medicine Doctor: Give
given Nurse: Medicine 1 2 medicine 2
Nurse: Medicine 2 given Doctor: Work finished Nurse: Medicine 2
given Nurse: Medicine 2 given
given Nurse: Medicine 2
Doctor: Work finished Nurse: Work finished given Nurse: Work finished
Nurse: Work finished Nurse: Work finished Doctor: Work finished
1, 2, Monitor.Enter(this); 3, Monitor.Exit(); 4, public static 3
Fd.WriteData("T1"); FileAccess Fd = new
FileAccess();
1, 2, lock() 3, 4, public static 2
Console.WriteLine("U Fd.UpdateAC("T2"); FileAccess Fd = new
pdated {0} record", FileAccess();
Cnt+1);
} Console.WriteLine("Er
Console.WriteLine("C } ror");