Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 15

using System;

using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;

namespace LabReviewBeforeExam
{
internal class Program
{
static void Main(string[] args)
{
/* ============================ Data Types with Implicit and Explicit
Casting ========================================*/

/*Ex(1): Write a program that allows employees to enter their names and
ID with printing both. By using string and and int variables*/

/* Console.WriteLine("Enter your Name:");


string employee_name = Console.ReadLine();
Console.WriteLine("Enter your ID");
int employee_ID = int.Parse(Console.ReadLine());
Console.WriteLine("The name is " + employee_name + " and his ID is " +
employee_ID);*/

/*
-----------------------------------------------------------------------------------
------------------------------------ */

/* EX(2): Write a program that enables user to calculate the Net Income
of XYZ company
* NOTE: Net Income = Revenues - Exepenses.
* NOTE: Revenues or exepenses may be double or float and we wanna in
this example to make it as rounded value.*/

/* Console.WriteLine("Enter XYZ Revenues:");


double revenues = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter XYZ Expenses:");
double expenses = Convert.ToDouble(Console.ReadLine());
int Net_Income = Convert.ToInt32(revenues - expenses);
Console.WriteLine("The Net Income of XYZ Company is: " +
Net_Income);*/ /*You can make it as rouned by using double and add .5d*/

/*
-----------------------------------------------------------------------------------
----------------------------------------- */

/*EX(3): write a calculator that take two numbers as string and then
printing as double numbers */

/* Console.WriteLine("Enter the first number:");


string num_1 = Console.ReadLine();
Console.WriteLine("Enter the second number:");
string num_2 = Console.ReadLine();
double No1 = Convert.ToDouble(num_1);
double No2 = double.Parse(num_2);
double sum = No1 + No2;
double sub = No1 - No2;
double div = No1 / No2;
double multi = No1 * No2;
Console.WriteLine("The Sum will equal: "+ sum);
Console.WriteLine("The Sub will equal: "+ sub);
Console.WriteLine("The Div will equal: "+ div);
Console.WriteLine("The Multi will equal: "+ multi);*/

/* ============================ Arithmetic Operators


========================================*/

/* EX(1): Write a program which allows you to Returns the division


remainder with Increases a reminder value by 1 */

/* Console.WriteLine("Enter the value of number ({0}): " , 1);


double num1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the value of number ({0}): " , 2);
double num2 = Convert.ToDouble(Console.ReadLine());

double The_Reminder = num1 % num2;


double the_total = ++The_Reminder;
Console.WriteLine("The Total after reminder and incremental will be:
"+the_total);*/

/* ============================ Logical Operators


========================================================*/

/* EX(1): Write a program that printing True if you enter the same
names and false if the names are different */

/* Console.WriteLine("Enter the first name:");


string first_name = Console.ReadLine();
Console.WriteLine("Enter the second name:");
string second_name = Console.ReadLine();
Console.WriteLine(first_name == second_name);*/

/* ============================ Conditional Statements


========================================================*/

/* EX(1): Write a program printing Studen’t name and BIS level 3 when
he enter his name and enter his BIS level */

/* Console.WriteLine("Enter Your Name:");


string name = Console.ReadLine();
Console.WriteLine("Enter your Level in BIS");
string BIS_Level = Console.ReadLine();

if(BIS_Level=="BIS Level 3" || BIS_Level=="level 3" || BIS_Level=="BIS


3" || BIS_Level == "bis 3" )
{
Console.WriteLine("Hello " + name + " from " + BIS_Level);
}
else
{
Console.WriteLine("Sorry You are not from BIS level 3");
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(2): Write program makes discount %5 for toys’ products to 11


years old */

/* Console.WriteLine("Enter age of the child:");


int age = int.Parse(Console.ReadLine());
Console.WriteLine("Which toy you want (train - ball)");
string toy_name = Console.ReadLine();
double discount;

if(toy_name=="train"&& age <= 11 || toy_name=="ball" && age <= 11)


{
Console.WriteLine("The price of train is ${0}", 50);
discount = 50 * 0.95;
Console.WriteLine("After discount (%5) the price will be: " +
discount);
}
else
{

Console.WriteLine("Your age is not avialable!");

}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(3): Write program that prints a grade based on your GPA like 3 or
3.5 or 4*/

/* Console.WriteLine("What is your GPA?");


double GPA = Convert.ToDouble(Console.ReadLine());

if (GPA < 2)
{
Console.WriteLine("Failed");
}
if(GPA>=2 && GPA <= 2.25)
{
Console.WriteLine("D");
}
if(GPA>=2.5 && GPA <= 2.75)
{
Console.WriteLine("C");
}
if(GPA>=3.00 && GPA <= 3.5)
{
Console.WriteLine("B");
}
if(GPA>=3.75 && GPA <= 4)
{
Console.WriteLine("A");
} */

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(4): Write program to dermine the input number whether odd or even
*/

/* Console.WriteLine("To check number odd or even please enter this


number:");
double odd_or_even = Convert.ToDouble(Console.ReadLine());
if (odd_or_even % 2 == 0)
{
Console.WriteLine(odd_or_even + " is even");
}
else
{
Console.WriteLine(odd_or_even + " is odd");
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(5): Write program to check whether input number is positive or


negative */

/* Console.WriteLine("What is your number?");


int num = Convert.ToInt32(Console.ReadLine());

if (num > 0)
{
Console.WriteLine(num+" is positive");
}
else
{
Console.WriteLine(num + " is negative");
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(6): Write program to check whether input number is positive and


odd at the same time or the opposite */

/* Console.WriteLine("Enter an integer:");
int number = int.Parse(Console.ReadLine());

if(number>=0 && number % 2 == 0)


{
Console.WriteLine("even and positive");
}
if(number<=0 && number % 2 == 0)
{
Console.WriteLine("even and negative");
}
if (number >= 0 && number % 2 != 0)
{
Console.WriteLine("odd and positive");
}
if (number <= 0 && number % 2 != 0)
{
Console.WriteLine("odd and negative");
}*/
/* NOTE: You can use another ways like nested if or else if as you want
*/

/* ============================ Looping Statements


===============================================================*/

/* EX(1): write program to print positive and negative numbers from


range that user will determe like -10 to 20
but the beginning number starts with negative number and the end
number is positive and output must be even and positive or negative
*/

/*By using for loop*/

/* int start_number = Convert.ToInt32(Console.ReadLine());


int end_number = Convert.ToInt32(Console.ReadLine());

for(int i = start_number; i<=end_number; i++)


{
if (i % 2 == 0 && i>0)
{
Console.WriteLine(i + " is even and positive");
}
if (i % 2 == 0 && i < 0)
{
Console.WriteLine(i + " is even and negative");
}
Console.WriteLine();
}
*/

/*By using while loop*/

/* int start_number = Convert.ToInt32(Console.ReadLine());


int end_number = Convert.ToInt32(Console.ReadLine());
int i=start_number;

while (i <= end_number)


{
if (i % 2 == 0 && i > 0)
{
Console.WriteLine(i + " is even and positive");
}
if (i % 2 == 0 && i < 0)
{
Console.WriteLine(i + " is even and negative");
}

i++;
}
*/

/*By using do while loop*/


/*int start_number = Convert.ToInt32(Console.ReadLine());
int end_number = Convert.ToInt32(Console.ReadLine());
int i = start_number;

do
{
if (i % 2 == 0 && i > 0)
{
Console.WriteLine(i + " is even and positive");
}
if (i % 2 == 0 && i < 0)
{
Console.WriteLine(i + " is even and negative");
}

i++;
} while (i <= end_number);*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(2): Write program that prints user’s name based on number of


times that user wants*/

/* Console.WriteLine("Enter your name:");


string name = Console.ReadLine();
Console.WriteLine("Enter number of times to print your name:");
int num_of_times = Convert.ToInt32(Console.ReadLine());

for(int i=0; i<num_of_times; i++)


{
Console.WriteLine(name);
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(3): Write program that make sum for even numbers only and
ignoring odd numbers */

/* Console.WriteLine("Enter values of numbers you want to make sum of


them:");
int values_of_numbers = int.Parse(Console.ReadLine());
int sum = 0;

for(int i=0; i<values_of_numbers; i++)


{
Console.WriteLine("The number of value ({0}):", i + 1);
int the_number = Convert.ToInt32(Console.ReadLine());

if (the_number % 2 == 0)
{
sum += the_number;
}

}
Console.WriteLine("The total of even numbers is: "+sum);*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(4): Write program to print number of columns and rows of stars


based on user requirements */

/* Console.WriteLine("Enter the number of rows:");


int rows = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the number of columns:");
int columns = Convert.ToInt32(Console.ReadLine());

for(int i =0; i<rows; i++)


{
for(int y =0; y<columns; y++)
{
Console.Write('*');
}
Console.WriteLine();
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(5): Write program to print this pattern: NOTE: you can change '*'
to be numbers or letters

*
**
***
****
*****

*/

/* for(int i =0; i < 5; i++)


{
for(int y=0; y<=i; y++)
{
Console.Write('*');
}
Console.WriteLine();
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(6): Write program to print this pattern:

*******
* *
* *
* *
* *
* *
*******
*/

/* int number = 7;

for (int i = 0; i < number; i++)


{
if (i == 0 || i == 6)
{
for (int j = 0; j < number; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
if (i >= 1 && i <= 5)
{
for (int j = 0; j < number; j++)
{
if (j == 0 || j == 6)
{
Console.Write("*");
}
else if (j >= 1 && j <= 5)
{
Console.Write(" ");
}
}
Console.WriteLine();
}

}*/

/* ============================ Array - One Dimensional


===============================================================*/

/* EX(1): Create a program that allows users to enter the number of


stars and then converting this value to be stars
like 5 to be ***** as five stars. */

/* Console.WriteLine("Write number of stars You want");


int number_of_stars = int.Parse(Console.ReadLine());
char[] stars = new char[number_of_stars];

for (int x = 0; x < number_of_stars; x++)


{
stars[x] = '*';
Console.Write(stars[x]);
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(2): write a pogram to determine the maximum and minmum number of


numbers range user determines*/
/* Console.WriteLine("Enter values of numbers:");
int num = Convert.ToInt32(Console.ReadLine());
int[] min_or_max = new int[num];

for(int i=0; i < num; i++)


{
Console.WriteLine("Enter the value of number ({0}):", i + 1);
min_or_max[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("The greater number is: " + min_or_max.Max() + " and
the smaller number is: " + min_or_max.Min()); */

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(3): Create a program that allows for entering 10 users for hiring
new employees in the XYZ company
then users who have age more than 30 and less than 21 will be
rejected from the application form.
You can use array for determing how to accept and reject and don’t
forget to allow users to enter their name and ages.

NOTE: Index starts from [0] not [1].


NOTE: When string[] Names = new string [5] Then [5] here which is
known as count.
NOTE: When Names[1]="BIS" it will mean that index number two have a
value which is "BIS" */

/* Console.WriteLine("Enter Your Name and Age"); //Title with "Enter


Your Name and Age"
string[] Names = new string[10]; // Create array with string Data
Type which consists of 10 elements as starting from [0] to [9]
int[] Ages = new int[10]; // Create array with int Data Type which
consists of 10 elements as starting from [0] to [9]

for (int x = 0; x < 10; x++)


{

Console.WriteLine("Your Name is:");


Names[x] = Console.ReadLine(); //User will enter his name
Console.WriteLine("Your Age is:");
Ages[x] = Convert.ToInt32(Console.ReadLine()); // user will enter
his age

if (Ages[x] <= 30 && Ages[x] >= 21) // if age of user is less


than or equal 30 and at the same time is greater than or equal 21

{
Console.WriteLine(Names[x] + " " + "Accepted!"); //Names[x]
changes for each time from [0] to [9] another index outside this range will be
error

else
{
Console.WriteLine(Names[x] + " " + "Rejected!");
}

Console.WriteLine(); //Make new line for each step of loop.


}
*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(4): Create a program that translate the following pattern to be


codeing:

*******
*******
*******
*******
*******

NOTE: You may use loop and array to translate this pattern to be
code. */

/* Console.WriteLine("Enter yes to see Code of this pattern");


Console.WriteLine();
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 7; y++)
{
Console.Write('*');
}
Console.WriteLine();
}
string[] Yes_OR_No = new string[2];
Yes_OR_No[0] = "yes";
Yes_OR_No[1] = "no";
Console.Write("Your Answer is: ");
string Answer = Console.ReadLine();
Console.WriteLine();
if (Answer == Yes_OR_No[0])
{
Console.WriteLine("The code is as following:");
Console.WriteLine();

for (int line = 0; line >= 0; line--)


{
for (int line1 = 0; line1 >= 0; line1--)
{
Console.WriteLine("for(int x=0; x<5; x++)");
}
for (int line2 = 0; line2 >= 0; line2--)
{
Console.WriteLine("{");
}
for (int line3 = 0; line3 >= 0; line3--)
{
Console.WriteLine(" for(int y=0; y<7; y++)");
}
for (int line4 = 0; line4 >= 0; line4--)
{
Console.WriteLine(" {");
}
for (int line5 = 0; line5 >= 0; line5--)
{
Console.WriteLine(" Console.Write('*');");
}
for (int line6 = 0; line6 >= 0; line6--)
{
Console.WriteLine(" }");
}
for (int line8 = 0; line8 >= 0; line8--)
{
Console.WriteLine("Console.WriteLine();");
}
for (int line9 = 0; line9 >= 0; line9--)
{
Console.WriteLine("}");
}
Console.WriteLine();

}
else
{
Console.WriteLine("As you like");
}
*/
/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(5): Write program for sorting names alphabetically. Using loop


and array:*/

/* Console.WriteLine("How many numbers of names you want to enter:");


int num = int.Parse(Console.ReadLine());
string [] sorting_names = new string[num];

for(int i=0; i<num; i++)


{
Console.Write("Enter name number {0}: ",i+1);

sorting_names[i] = Console.ReadLine();

}
Console.WriteLine("Names after rearrangement are:");
Array.Sort(sorting_names);
foreach(string rearrange in sorting_names)
{
Console.WriteLine(rearrange);
}*/

/* ============================ Array - Two Dimensional


===============================================================*/
/* Ex(6): Write program to print this output:

Matrix you entered

2 3 4
5 6 7
8 9 1
*/

/* Console.WriteLine("Matrix you entered:");


int[,] Matrix_2D = new int[3, 3] { { 2, 3, 4 }, { 5, 6, 7 }, { 8, 9, 1
} };

for(int i=0; i<3; i++)


{
for(int y=0; y<3; y++)
{
Console.Write("{0}\t",Matrix_2D[i, y]);
}
Console.WriteLine();
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(7): write a program to allow users to make his matrix which 3*3
or 2*2 or 5*5 based on user’s requirements: */

/* Console.WriteLine("Enter the number of rows for the matrix:");


int rows = int.Parse(Console.ReadLine());

Console.WriteLine("Enter the number of columns for the matrix:");


int columns = int.Parse(Console.ReadLine());

// Declare a 2D array based on user input


int[,] matrix = new int[rows, columns];

// Input values for each element in the matrix


Console.WriteLine("Enter the matrix elements:");

for (int i = 0; i < rows; i++)


{
for (int j = 0; j < columns; j++)
{
Console.Write("Enter element at position [{0},{1}]: ",i,j);
matrix[i, j] = int.Parse(Console.ReadLine());
}
}

// Print the two-dimensional matrix


Console.WriteLine("The entered matrix is:");

for (int i = 0; i < rows; i++)


{
for (int j = 0; j < columns; j++)
{
Console.Write(matrix[i, j] + "\t");
}
Console.WriteLine(); // Move to the next row for better
readability
}

*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(8): By using two-dimensional array and for loop you are required
to write program that prints the following pattern:

*********
*********
*********
*********
*********
*/

/* char[,] starts_figure = new char[5, 9];


for(int i=0; i<5; i++)
{
for(int y=0; y<9; y++)
{
starts_figure[i, y] = '*';
Console.Write(starts_figure[i,y]);
}
Console.WriteLine();
}*/

/* ============================ Methods
=============================================================== */

/* EX(1): By using only one method write a program that printing the
following output:

the name is ahmed and the age is 24


the name is mohammed and the age is 21
the name is mostafa and the age is 24
*/

/* name_age("ahmed", 24);
name_age("mohammed", 21);
name_age("mostafa", 24);*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(2): By using method retrun sum numbers from 2 to 6:*/

// Console.WriteLine("The sum is " + odd_numbers(2,3,4,5));

/*
-----------------------------------------------------------------------------------
------------------------------------- */
/* EX(3): reference ‫* هذا مثال توضيحي فقط الستخدام الدالة في وجود‬/

/* int i = 20;
// using_reference(i);
Console.WriteLine(i); // i before

// when we use ref we consder i and num as in the same memory as


follow:

using_reference(ref i); // i after


*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* EX(4): By using loop, methods and array write a program to take the
average of numbers user will enter them firstly: */

/* Console.WriteLine("Enter the number of values:");


int num_of_values = Convert.ToInt32(Console.ReadLine());
int[] val= new int[num_of_values];
the_average(num_of_values, val);
*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* Accoring to the example (1) of methods */

/* static void name_age(string name, int age)


{
Console.WriteLine("the name is " + name + " and the age is " + age);
}*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* Accoring to the example (2) of methods */

/* static int odd_numbers(int num1, int num2, int num3, int num4)
{

int sum = num1 + num2 + num3 + num4;


return sum;

}*/
/*
-----------------------------------------------------------------------------------
------------------------------------- */
/* Accoring to the example (3) of methods */

/* static void using_reference(ref int num)


{
num = 30;
Console.WriteLine(num);
}
*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

/* Accoring to the example (4) of methods */


/* static void the_average(int num, int[] the_val)
{
int sum = 0;
int the_average = 0;

for(int x=0; x<1; x++)


{

for(int i=0; i<num; i++)


{
Console.Write("the value of number {0} is ", i + 1);
the_val[i] = Convert.ToInt32(Console.ReadLine());
sum += the_val[i];
the_average = sum / the_val[i];
}

Console.WriteLine(the_average);

}
}
*/

/*
-----------------------------------------------------------------------------------
------------------------------------- */

You might also like