using System;
using System.Runtime.InteropServices;
class Test
{
[DllImport ("msvcrt")]
static extern char _getch();
static void Main()
{
char c;
Console.Write("This is your Programming Language Knowledge Test of C, developed in C# console application by The \"Amit Ranjan\".\n");
Console.Write("There are 20 multiple Choice Question of 5 marks each.\n");
Console.Write("Total marks :- 100\nTime:- 90 min\nEvery Question is compulsary.");
Console.Write("First read questions carefully and then answer it.");
z:Console.Write("\nDo You Want To Proceed (y/n) :- ");
c=_getch();
Console.WriteLine(c);
switch(c)
{
case 'Y':
case 'y': Test t=new Test();
t.detail();
break;
case 'N':
case 'n': Console.Write("\nGood Luck, and Be Prepared for the next time\n");
break;
default: Console.Write("\nInvalid Choice");
goto z;
}
_getch();
}
void detail()
{
string name;
char[] password=new char[20];
char[] pw=new char[20];
int i;
Console.Write("\nEnter your name :- ");
name=Console.ReadLine();
Console.Write("Enter password :- ");
i=0;
while(true)
{
pw[i]=_getch();
if(pw[i]==' ' || pw[i] == '\r')
{
/*pw[i]='\0';
password[i]='\0';*/
break;
}
else
{
password[i]=pw[i];
Console.Write("*");
}
i++;
}
Console.Write("\n");
string s=new string(password);
if(string.Compare(s,"najnartima")==0)
{
Console.WriteLine("Welcome! Miss./Mrs./Mr."+ name);
Console.Write("Now best of luck for your test.");
Console.Write("\nPress any key............");
_getch();
test();
}
else
{
Console.Write("Sorry! Invalid password.You are not elegible for this test.");
}
}
void test()
{
int c,w;
char ans;
c=0;w=0;
Console.Clear();
Console.Write("\n1. What do you mean by Conditional Compilation ?\n");
Console.Write("a. It is taken care of by the compiler\nb. It is setting the compiler options conditionally\nc. It is compiling a program based on condition\nd. None of Above\n");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='C' || ans=='c')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n2. Originally C was developed as ? \n");
Console.Write("a. System Programming Language\nb. General Purpose Language \nc. Data Processing Language \nd. None of above\n");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='A' || ans=='a')
{c++; Console.Write("\nCorrect");}
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("3. Minimum number of temporary variable needed to swap the contents of 2 variable is ? \n");
Console.Write("a. 1\nb. 2\nc. 3\nd. 0");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='D' || ans=='d')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); } Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n4. *ptr++ is equivalent to ?\n");
Console.Write("a. ptr++\nb. *ptr\nc. ++*ptr\nd. None of Above");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='D' || ans=='d')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n5. Expression C=i++ Causes ?\n");
Console.Write("a. Value of i is assigned to C and then I is incremented by 1\nb. i to be incremented by 1, and then value of i assigned to C\nc. Value of i assigned to C\nd. i to be incremented by 1");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='a' || ans=='A')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n6. Declaration int *(*p) int(*a)(i) is ?\n");
Console.Write("a. A pointer to function that accepts an integer argument and returns an integer\nb. A pointer to a, which returns an integer\nc. A pointer to subroutine, which returns result of evaluation\nd. None of Above");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='A' || ans=='a')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n7. Null pointer and UN-initialized pointers are same ?\n");
Console.Write("a. True\nb. False\nc. Varies from program to program\nd. None of Above");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='B' || ans=='b')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n8. In which header file Null macro is defined ? \n");
Console.Write("a. stdio.h and stddet.h\nb. iostream.h\nc. string.h\nd. Preprocessor");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='A' || ans=='a')
{ c++; Console.Write("\nCorrect");}
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n9. Null pointer is ?\n");
Console.Write("a. A pointer which does not point anywhere\nb. Pointer defined with name Null\nc. A pointer that returns 0 values\nd. None of Above");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='A' || ans=='a')
{ c++; Console.Write("\nCorrect");}
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n10. Null macro is ?\n");
Console.Write("a. A macro with name Null\nb. A macro which represents Null pointer\nc. A macro defined with no name\nd. None of Above");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='B' || ans=='b')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n11. Which of the following is not true in context of C language ?\n");
Console.Write("a. It is array of characters\nb. Last character of character array is always \\0\nc. C inserts the null character automatically\nd. Any string in C can be read by the function _getchar()");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='B' || ans=='b')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n12. Which of the following operations can not be perform on pointers in C ?\n");
Console.Write("a. Addition of two pointers\nb. Subtraction of a number from a pointer\nc. Subtraction of one pointer from another\nd. Addition of a number to a pointer");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='C' || ans=='c')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n13. Which is not a programming language?\n");
Console.Write("a. C\nb. C#\nc. F#\nd. Z#");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='D' || ans=='d')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n14. What is the output of C statement 7.5 % 3 ?\n");
Console.Write("a. 1.5 \nb. 1\nc. No output\nd. 2");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='B' || ans=='b')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n15. Any program in C has access to three standard files?\n");
Console.Write("a. standard input file, standard output file, standard error file\nb. stdin, stdout, stderr\nc. keywords, screen, stderr\nd. All of above\ne. None of Above");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='C' || ans=='c')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n16. An identifier in C ?\n");
Console.Write("a. is a name of thing such as variable and function\nb. is made up of letters, numerals and the underscore\nc. can contain both uppercase and lowercase letters\nd. All of above\ne. None of Above");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='C' || ans=='c')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n17. The single character input/output functions are ?\n");
Console.Write("a. scanf( ) and printf( )\nb. getchar( ) and printf( )\nc. scanf( ) and putchar( )\nd. getchar( ) and putchar()\ne. None of Above");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='C' || ans=='c')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n18. Precedence determines which operator ?\n");
Console.Write("a. is evaluated first\nb. is most important\nc. is fastest\nd. Operates on the largest number\ne. None of Above");
Console.Write("\nAns : - ");
ans=_getch(); Console.WriteLine(ans);
if(ans=='B' || ans=='b')
{ c++; Console.Write("\nCorrect");}
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n19. Who develope the C programming language?\n");
Console.Write("a. Charls Babbage\nb. Dennis Richard\nc. Dennis Ritchie\nd. James Gosling\ne. None of them");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='C' || ans=='c')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key for next question........");
_getch();
Console.Clear();
Console.Write("\n20. The two operators && and || are ?\n");
Console.Write("a. Arithmetic operator\nb. Equality operators\nc. Logical operators\nd. Relational operators\ne. None of Above");
Console.Write("\nAns : - ");
ans=_getch();
Console.WriteLine(ans);
if(ans=='D' || ans=='d')
{ c++; Console.Write("\nCorrect"); }
else
{ w++; Console.Write("\nIncorrect"); }
Console.Write("\nPress any key to get your result ........");
_getch();
Console.Clear();
result(c,w);
}
void result(int c,int w)
{
Console.Write("You had given {0} right answers and {1} wrong answers\n",c,w);
Console.Write("Your total marks is {0}\n",c*5);
if(c*5>=90)
Console.Write("Your Grade is : \'A+\'");
else if(c*5<90 && c*5>=80)
Console.Write("Your Grade is : \'A\'");
else if(c*5<80 && c*5>=70)
Console.Write("Your Grade is : \'B+\'");
else if(c*5<70 && c*5>=65)
Console.Write("Your Grade is : \'B\'");
else if(c*5<65 && c*5>=60)
Console.Write("Your Grade is : \'C\'");
else
Console.Write("Sorry, You Fail!!!!!Better luck next time");
}
}
Output:-
No comments:
Post a Comment