Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Final Programming( c#)

Dr/ Hamed Abu Alnsr


Programming Language 1

Some important points which you should be fully aware of in chapter1


 Computer software. or simply software, is a collection of data of computer instructions that
tell the computer how to work
 A program is a collection of instructions to perform (a specific task)
 A computer program is developed by a computer programmer. The programmer writes the
source code
representing the program instructions using one of the programming languages.
 There are several programming languages with different (syntax and features)
 Once the source code is ready, it can be converted into a computer program using the
compiler such as c# or c++ Or interpreted such as python (‫)برنامج مكتوب بلغة اﻻلة‬
 The compiler itself is a program that can convert source code into an executable program
 In Structured Programming, the code is divided into functions or modules. It is also known as
modular programming.
 Structured Programming easy for the programmer to test and debug. It is also easy to do
modifications without changing the whole program.
 Java and c# are examples of Structured Programming
 In Unstructured Programming, the code is written as a single whole block. The whole
program is taken as a single unit. It is harder to change in the program.
 BASIC,COBOL,and FORTRAN
are examples of Unstructured languages
 *Structured languages vs unstructured
 A flowchart is simply a graphical representation of steps. It shows steps in sequential order
 A flowchart can also be used to define a process or project to be implemented.
 *Flowchart svmbols
 Algorithm is a set of step-by-step instructions to solve a problem.
 Psendocode An English-language-like representation of an algorithm. Does not have a
standard syntax and can take different forms. It is a compact and informal high-level
description of a program. Not a programming language and cannot be compiled into a
program.
Some important points which you should be fully aware of in chapte2
 *A C# program consists of a set of one or more namespaces, each namespace contains a
set of one or more classes. and each class contains a set of one or more methods.
 A namespace may contain other namespaces as well.

Page |1
Programming Language 1

 Each method, in turn, may contain a set of ore or more statements and each statement represent a
command to execute
 using System; means that we can use classes from the System namespace.
 Write( )vs WriteLine()
 *Single line vs multiple line comments
 variables are containers for storing data values
 Constant variables
 It's not allowed to define constant variable without assigning value to it
 For numeric values, the + character works as a mathematical operator
 To define identifier;
 It is recommended to use descriptive names in order to create understandable and maintainable
code
 Names can contain only letters. digits and the underscore ()
 Names must begin with a letter or an underscore.
 Names cannot contain a white space.
 Names are case sensitive (e.g. my Var and my var are different).
 Reserved words (e.g. int or double) can not be used as names.

Some important points which you should be fully aware of in chapte3,4


 System.Int32 means int
 System.Int64 means long
 System.Single means float
 System.Double means double
 Integers and long stores integer (positive or negative) values
 Float and doubles stores fractional numbers → ..
 Float store 6 to 7 digits after decimal point
 Double stores up to 15 digits
 Int size is 4 byte , 32 bit while long is 8 byte,64 bit
 Float size is 4 byte.32 bit. While double is 8 byte,64 bit
 Scientific number is numbers that contains "e" such 4e7 which indicates to 4 *107
 scientific numbers must be float or double
 The precision of a floating point value indicates how many digits the value can have after the decimal point
 Implicit Casting (automatically); converting a smaller type to a larger type size
 char → int →long → float → double
 Explicit Casting (manually); converting a larger type to a smaller size type
 Double → float → long → int → char
 x+=5 means add 5 to x and store the result in x " x=x+1"as same x++,++x
 % means modulus
 && means and. ,I| means or , I means not →logical operator
 >,>,<,<,-,1=
 Console.WriteLine(!(true)); will print false

Page |2
Programming Language 1

Some important points which you should be fully aware of in chapte5 & 6
 Use if to specify a block of code to be executed. if a specified condition is true
 Use else lo specify a block of code to be executed, if the same condition if false
 Use else if to specify a new condition to test, if the first condition is false
 Use switch to specify many alternative blocks of code to be executed
 It is always legal in C4 to nest if statements. which means you can use one if or if-else statement
 inside another if or else statement(s).
 nested if is able to reduce the number of comparisons
 the switch statement to select one of many code blocks to be executed.
 The switch expression is evaluated once
 The value of the expression is compared with the values of each case
 If there is a match, the associated block of code is executed
 A break can save a lot of execution time because it "ignores" the execution of all the rest of the code
 in the switch block.
 The default keyword is optional and specifies some code to run if there is no case match;

1- To write single line comment in c# you must start the line by...
a.@ b./* C. // d.*/

2- To write multiple line comment in c# you must start the line by...
a. @ b./* C.// d.*/

3- To write multiple line comment in e# you must ends the comment lines by...
a.@ b./* C.// d.*/

4- What of the following is allowed to name the variable?


a. Must begin with letter or underscore b. Don't contain any space
c. Contains letter and digits and underscore d. All of above

5- Which of the following is the correct ways to set a value 3.14 in a variable pi such that it
cannot be modified?
A. float pi =3.14 F; B. #define pi 3.14 F c. const float pi =3.14 F; D. const float pi; pi =3.14 F;

6. Every C# statement ends with a____________

a. @ b. * c. ; d.{

7. Integer data type variable can store __________

a. Positive value b. Negative value c. Both a&b d. Scientific numbers

8. which of the following statements can increment the value of variable(x) by 1

A. x++; B. ++x; C. x+=1 d. x=x+1; E. all of above

Page |3
Programming Language 1

9. what is the output of the following code

A. My name is mohammed B. mohammed C.my name is mohamed D. my name is mohammed

10. A C# program consists of only one e namespace?


a. True b. False

11. A namespace may contain other namespaces as well.


a. True b. False
Note; / forward slash that used in single line comment
\ back slash that used in \n , \t,\b,\", \'and \\

12.Single line comment can be used to comment a block of code


a. True b. False

13. Data type specifies the ---and -----of variable value.


a. Data and value b. Value and type c. Size and type d. Non of above

14. To declare two integer variables x. y what is allowed


a. int x;y; b. intx,int y; c. int x y; d. int x,y;

15.Bool variable has size-in memory


a. 2 byte b.4 byte c. 1 byte d.12 byte

16. What is the output of this code


Console.WriteLine ((5+4) +"," +("5"+"4"));
a. 54.54 b. 5+4,5+4 c. 9.54 d. 9.54

17. What is the output of this code


Console.WriteLine(true && true);
a. True b. false

18. What is the output of this code


Console.WriteLine(!(true && true));
a. true b. false.

Note

Console WriteLine (5>10))the output here is. "False

Page |4
Programming Language 1

19. To increase the value of variable x by 5

a. x=+5; b. x+=5; c. x+=5; d. x=5;

20.What is the output of this code

int x=3;
int y=10;
if (x < y)
Console.writeLine (x<y)
else
Console.WriteLine(x>y);
a. x<y b. x>y c. true d. false

21.To take input from user we must write

a. Console.WriteLine(); b. Console.ReadLine(); c. Console.ReadLine(input); d. input

22. The code x**

a. will multiply x by 3 b. will multiply x*x c. This will leads error

23. What is the output of this code?

static void Main (string []args)


{
Int x=0
Int y= 10%10;
If (x==y)
Console.Write(“I’m in if” )
else
Console.WriteLine (“I’m in else” )
Console.WriteLine (“I’m in main” )
}

a. i'm in if i'm in main b. i'm in else i'm in main c. i'm in main d.error

24. what is the output of this code

If (5<10)
{
Console.WriteLine("welcome");
}
Else
{
break;
}
a. welcome b. error c. nothing d. break;

Page |5
Programming Language 1

25. What is the output of this code

string name ="\"mohammed\"


Console.WriteLine("my name +name);

A. My name is "mohammed" B. This code will leads syntax error


C. my name is "mohammed" D. my name is \"mohamme\”

26.What is the output of this code

Int x=5 , y=6,z=50;


Console. WriteLine( x+y+z );

A. 5650 B. 61 c. 44 d. 11

27. What is the output of this code

Int x=5. y=6 . z= 4;


Console.WriteLine (x+y*z);

A. 5650 B.61 c. 29 d. 44

28.What is the output of this code

double num =20.6;


int num2 =(int)num;
Console. WriteLine(num2);

A.20 b. 20.6

29.What is the output of this code.

double num= 20.6;


int num2 = Convert.Tolnt32 (num)
Console.WriteLine(num2);

A.20 B.20.6 C.21 D.29

Page |6
Programming Language 1

30. What is the output of this code.

double num = 20.2;


int num2=Convert.Tolnt32(num)
Console.WriteLine(num2);

A.20 B.20.6 C.21 D.29

31.What is the output of this code?


Bool x=false;
Console.WriteLine(Comvert.Tolnt32(x));

a. 0 b.1 C. True d. False

32.What is the output of this code

Bool x = false;
//Console.WriteLine(Convert.Tolnt32(x));

a. 0 b.1 c. True d. This code is true but not have any printing statement

33. To take an integer input from user what of the following is correct

a. int num = Convert.Tolnt32(Console.ReadLine()); b. int num =int.Parse( console.ReadLine());

C. int num=Convert.Tolnt64( Console.ReadLine() ); d. both a and b

34. To take input from user what is valid ?

a. int input = Console.ReadLine(); b. string input= Console.ReadLine();

C. double input = Console.ReadLine(); d. long input = Console.ReadLine();

VIIII 35. What is the output of the following code

Int num=5;

Console.WriteLine (num++ +","+ ++num);

a. 5.6 b. 5.5 C. 6.7 d.5.7

36. A variable with a float type can be implicitly converted to

a. int b char c. bool d. double

Page |7
Programming Language 1

37.variable with bool type can implicitly converted to string

a. True b. False

38. Statement x+ will increase the variable x by 1

a. True b. False

39. Statement x=+1; will increase the variable x by 1

a. True b. false

40. Convert.ToLong (); will convert value to long type. Correction


a. True b. false //convert.Tolnt64();

41. Convert.Tolnt64(); will convert value to int type.

a. True b. false

42 .Convert.ToFloat (); will convert value to float type. Correction

a. True b. false //convert.ToSingle();

43.The expression.......Is true if both X and y are true?

a. X ll y. b. X|y c. X!y d. X&y

44. The operator -is used to concatenate two strings value

a. * b. / c. + d. !

Page |8
Programming Language 1

45.What is the output of this code?

int x=0;
if (++x==0)
{
Console.WriteLine(x);
x
}
else
{
Console.WriteLine ("welcome");
}
A. X B.1 C.0 D. welcome

46.The ------keyword that specifies what do you do when the condition of if is not true?

A. Otherwise B. else C. if D. default

47. Each case in c# must ended by------

A. Continue B. break C. case D. none of above

48. In switch statement what is equivalent to else in if?

A. Otherwise B. else C. if D. default

49.The default statement is optional

A. true B. false

50. The size of string value is----byte per character

a.1 b.2 c.3 d.4

51. The data type that able to store this value ‘A’

a. int b. String c. Char d. bool

Page |9
Programming Language 1

52.The data type that able to store this value "A"

a. Int b. String c. Char d. Bool

53.The precision of float datatype is 15

a. True b. False

54. The precision of double is 6 to 7

a. True b. False

55.Scientific numbers can define as int or long

a. True b. False

56. The value of y is true if the x is false

booly=x!;
bool x=false ;
Console.WriteLine(y) ;

a. True b. False

57. The value of y is true if the x is false

bool x=false;
bool y=!x
Console.WriteLine(y);

a. True b. false

58.What is the error here

A B C

Int x =10 ; Int x =10 ; const int x =10 ;

Sring x = “ mohammed” ; x= “ mohammed” x= 20;

59. else block can be written without if?

a. true b. false

P a g e | 10
Programming Language 1

60.What is the output of this code

int x=100;

x=+1 ;

Console.WriteLine(x)

A.100 B.101 C.1 D.110

61.What is the output of this code

int input=Console.ReadLine();

this code will leads an error message [ Cannot implicitly convert type 'string'to 'int]

62.A string variable contains a collection of characters surrounded by-----

a. double quotes b. single quotes c. no quotes d. slash

63.Correct the following code

String name = "my name is ""mohammed"":

The solution to avoid this problem, is to use the backslash escape character (1) to turns special characters into string
characters

String name = "my name is \"mohammed \"";

64. What is the output of this this code

string x="true" ;

Console.WriteLine(y);|

a. Error b. True C. 0

65. What will do if Note: If you enter wrong input ( e.g text in a numerical input)

you will get an exception/error message

System Format Exception: Input sting was not in a

correct format

P a g e | 11

You might also like