You are on page 1of 9

5/10/2017 Assignment 1

VISUAL PROGRAMMING

NAME: SYED NAJAM UL HASSAN NAQVI


REG NO: FA15-BCS-146
CLASS: BCS-5C
SUBMITTED TO: DR. JAMAL HUSSAIN SHAH
1. Write the program to print the following things: your name, father name,
current institute.

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


String name = Console.ReadLine();
Console.WriteLine("Enter your Father name :");
String f_name = Console.ReadLine();
Console.WriteLine("Enter your Institute name :");
String institute = Console.ReadLine();
Console.WriteLine(" Your name = {0} \n Your father name =
{1} \n your Institute = {2} :", name, f_name, institute);
Console.ReadKey();

2. Write a program to assign values to different variables at the time of


declaration. Print the assign values on the computer screen.

static void Main(string[] args)


{
int a = 1000;
int b = 2000;
Console.WriteLine(" Value of a " + a + "\n Value of b " +
b);
Console.ReadKey();
}

3. Write a program to perform the arithmetic operations by using all


arithmetic operations. Also print the results on the screen.

int a = 100, b = 2000, c = 430, d = 950;


int e, f, g, h;
e = a * b;
f = d + b;
g = c - d;
h = c % d;
Console.WriteLine("the values you entered are \n a = {0} \n
b ={1} \n c = {2} \n d = {3} :", a, b, c, d);
System.Console.WriteLine("The Multiplication of two numbers
a and b is ={0} \n The adition of two numbers d and b is
={1} \n The subtraction of two numbers c and d is ={2} \n
The Modulus of two numbers c and d is ={3} \n", e, f, g, h);
Console.ReadKey();

4. Write the program to print the radius of the circle.

static void Main(string[] args)


{
const double pi = 3.14;
double C;
double radius;
Console.Write("Enter Circumferance :");
C = Convert.ToDouble(Console.ReadLine());
radius=C/(2*pi);
Console.WriteLine(" Radius of Circle is :{0}",radius);
Console.ReadKey();
}
5. Write the program to print the area of the circle and rectangle.

static void Main(string[] args)


{
double area;
double width;
double length;
Console.Write("Enter width of rectangle");
width = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter length of rectangule");
length = Convert.ToDouble(Console.ReadLine());
area = length * width;
Console.WriteLine("Area of Rectangule is :{0}",area);
double radius;
Console.Write("Enter Radius of Circle: ");
radius = Convert.ToDouble(Console.ReadLine());
const double pi = 3.14;
area = pi * (radius * radius);
Console.WriteLine("Area of Circle is :{0}", area);
Console.ReadKey();

6. Write a program to assign two variables by assignment statement.


Interchange the values and print the result on the screen.

{
int a, b, c = 0;
Console.WriteLine("Enter two number");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = a;
a = b;
b = c;
System.Console.WriteLine("The Swaped Value of A={0} B=
{1}", a, b);

Console.ReadKey();

7. Write a program to assign the numeric values to a variable year. Calculate


the number of months, and print on the screen.

{
double Year, Month;
Console.WriteLine("Enter years:");
Year = double.Parse(Console.ReadLine());
Month = Year * 12;
System.Console.WriteLine("Num of months in your given
year:{0}", Month);
Console.ReadKey();

}
8. Write a program to get name and age of a person. Calculate the age in
months and number of days with the name of person.

{
String Name;
int Year, Month, Days;
Console.WriteLine("Enter Your Name:");
Name = Console.ReadLine();
Console.WriteLine("Enter Your Age In Years:");
Year = int.Parse(Console.ReadLine());
Month = Year * 12;
Days = Year * 365;
Console.WriteLine("Your Name:{0} \n Your Age in Months:{1}
\n Your Age in Days :{2}", Name, Month, Days);
Console.ReadKey();

9. Write a program in C# to read the name of a student and marks obtained


on three subjects C++, OS and EDP. Calculate the total and average. Input
the data using system.Readline() object. Each subject has maximum of 100
marks.

static void Main(string[] args)


{
string sname;
double Cplus;
double OS;
double EDP;
Console.Write("Enter Student name: " );
sname = Console.ReadLine();
Console.Write("Enter CPlusPlus marks(max=100): ");
Cplus =Convert.ToDouble( Console.ReadLine());
Console.Write("Enter OS marks(max=100):");
OS=Convert.ToDouble( Console.ReadLine());
Console.WriteLine("Enter EDP Marks(max=100): ");
EDP = Convert.ToDouble(Console.ReadLine());
double total;
double average;
total = Cplus + OS + EDP;
average = total / 3;
Console.WriteLine("NAME :{0}", sname);
Console.WriteLine("CPLUS :{0}", Cplus);
Console.WriteLine("OS :{0}", OS);
Console.WriteLine("EDP :{0}", EDP);
Console.WriteLine("Total marks :{0}", total);
Console.WriteLine("Average marks :{0}", average);
Console.ReadKey();

10. Write a program in C# t o read temperature in Fahrenheit. Convert the


temperature to Celsius degree by using formula c=5/9(f-32).

{
double F, C;
Console.WriteLine(" Enter Temprature in Fahrenheit=");
F = double.Parse(Console.ReadLine());
C = ((F - 32) * 5) / 9;
Console.WriteLine("Temprature In Celsius ={0}", C);
Console.ReadKey();

11. Write a program to input a number. If the number is divisible by 3 then


print the message on the screen that the number is divisible by three.

{
int j, k = 3;
j = int.Parse(Console.ReadLine());
j = j % k;
if (j == 0)
{
Console.WriteLine("the number is divisible by three");
}
else
{
Console.WriteLine("the number is not divisible by
three");
}
Console.ReadKey();
}

12. Write a program to input a number. If the number is prime number then
print the message on the screen that prime number.
{
int n, i;
Console.WriteLine("Enter a positive integer:");
n = int.Parse(Console.ReadLine());
for (i = 2; i <= n / 2; ++i)
{
if (n % i == 0)
{
Console.WriteLine("Not prime");
break;
}
}
Console.ReadKey();
}

13. Write a program to calculate the electric bill. The rates of electricity per
unit are as follow:

If the units consumed are equal or less than 300. Then the cost is Rs.
3/- per unit.

If units consumed are more than 300, then the cost is Rs. 3.5/- per unit
and a surcharge of 5% of the bill is added.
{

double n, m, o;
Console.WriteLine("Enter the consumed units=");
n = double.Parse(Console.ReadLine());
if (n <= 300)
{
m = n * 3;
Console.WriteLine("You bill = {0}", m);
}
else if (n > 300)
{
m = n * 3.5;
= (m / 100) * 5;
Console.WriteLine("You bill = {0}", 0);
}
Console.ReadKey();
}

14. Write a program to input two values from the keyboard and then to print
the larger number on the computer screen.
{
double n, m;
Console.WriteLine("Enter 1st number=");
n = D.Parse(Console.ReadLine());
Console.WriteLine("Enter 2nd number=");
m = double.Parse(Console.ReadLine());
if (n > m)
{
Console.WriteLine("n is greater");
}
else if (m > n)
{
Console.WriteLine("m is greater");
}
else if (m = n)
{
Console.WriteLine("Equal to each other");
}

Console.ReadKey();
}

15. Write a program to calculate the net pay of an employee. Input the basic
pay and calculate the net pay as follow:

House rent is 45% of the basic pay.

Medical allowance is 2% of basic if basic is greater than Rs. 5000/-. It


is 5% of basic pay if the pay is less than Rs. 5000/-.

Conveyance allowance is Rs. 96/- if basic pay is less than Rs. 5000/-. It
is Rs. 193/- if then basic pay is more than Rs. 5000/-.

Net pay is calculated by adding basic pay, medical allowance,


conveyance allowance and house rent.
static void Main(string[] args)
{
double net_pay,basic_pay;
double HR, MA, CA;
Console.WriteLine("Enter your Basic Pay: ");
basic_pay = Convert.ToDouble(Console.ReadLine());
if (basic_pay < 5000)
{
MA = (basic_pay * 5) / 100;
}
else
{
MA = (basic_pay * 2) / 100;
}
HR = (basic_pay * 45) / 100;
if (basic_pay < 5000)
{
CA = 96;
}
else
{
CA = 193;
}
net_pay = basic_pay + HR + MA + CA;
Console.WriteLine("Basic Pay:{0} ",basic_pay);
Console.WriteLine("Medical Allowance:{0} ", MA);
Console.WriteLine("House Rent:{0} ", HR);
Console.WriteLine("Conveyance Allowance:{0} ", CA);
Console.WriteLine("Net Pay:{0} ", net_pay);
Console.ReadKey();

16. Write a program to find out the grade of a student based on the marks
obtained in three subjects. The grade is calculated as:

If average is greater than 80, grade A.

If average is less than 80 and greater than 33, grade is B.

If average is less than 50 and greater than 33, grade is B.

If average is less than 33, grade is F.

static void Main(string[] args)


{
double sub1;
double sub2;
double sub3;
{
string grade;
Console.Write("Enter the First Subject marks: ");
sub1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the second Subject marks: ");
sub2 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the three Subject marks: ");
sub3 = Convert.ToDouble(Console.ReadLine());
double total = sub1 + sub2 + sub3;
double avg = total / 3;
if (avg > 80)
grade = "A";
else if ((avg > 33) && (avg < 50))
grade = "C";
else if ((avg > 33) && (avg < 80))
grade = "B";
else
grade = "F";

Console.Write("Your Grade is : {0}", grade);


Console.ReadKey();

17. Write a program to perform simple arithmetic operation by using nested


if-else structure.
static void Main(string[] args)
{
int a = 55;
int b = 45;
int mul;
int add;
if (a > 50)
{
if (b > 100)
{
mul = a * b;
Console.WriteLine("Multiplication perform:{0} ", mul);
}
else
{
add = a + b;
Console.WriteLine("Addition perform:{0} ",add);
}
}
else
Console.WriteLine("No Operation perform ");
Console.ReadKey();
}

18. Write a program to perform simple arithmetic operation by using


switch statement.
static void Main(string[] args)
{
int num1;
int num2;
double result;
Console.Write("enter your first number");
num1=Convert.ToInt32(Console.ReadLine());
Console.Write("enter your second number");
num2=Convert.ToInt32(Console.ReadLine());
int choose;
Console.WriteLine(" 1 for addtion:");
Console.WriteLine(" 2 for Subtraction:");
Console.WriteLine(" 3 for division:");
Console.WriteLine(" 4 for Multiplication:\n");
Console.WriteLine(" \t\t Enter your Choose");
choose=Convert.ToInt32(Console.ReadLine());
switch (choose)
{
case 1:
result = num1 + num2;
Console.WriteLine("Result is:{0}",result);
break;
case 2:
result = num1 - num2;
Console.WriteLine("Result is:{0}", result);
break;
case 3:
result = num1 / num2;
Console.WriteLine("Result is:{0}", result);
break;
case 4:
result = num1 * num2;
Console.WriteLine("Result is:{0}", result);
break;
default :
Console.WriteLine("Invalid Choose");
break;

}
Console.ReadKey();

19. Write a program to input a single character and print a message it is a


vowel if it is vowel otherwise print message it is a consonant. Use if-
else structure and OR (||) operator.
public static void Main(string[] args)
{
char character;
Console.Write("Enter an alphabet: ");
character = Char.Parse(Console.ReadLine());

if((character >= 'A' && character <= 'Z')||character >=


'a' && character <= 'z')
{
if (character == 'a' || character == 'A' ||
character == 'e' || character == 'E'
|| character == 'i'|| character == 'I' ||
character == 'o' || character == 'O'
|| character == 'u' || character == 'U')
{
Console.WriteLine(character + " is a vowel");
}
else
{
Console.WriteLine(character + " is a
consonant");
}
}
else
{
Console.WriteLine(character + " is not an
alphabet");
}

You might also like