You are on page 1of 15

Assignment no 1

Name = Syeda Anmol Zahra Jaffary

Department = BSE

Section = 1-B

Enrollment Number: 02-131212-060

Subject: Computer Programming

Task # 01
Write a c# program to find that a person is allowed to sit in BSE-1. (Hint: He is allowed if he belongsto BUKC
and he is the student of first semester and he is a student of software engineering).

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.WriteLine(" \"{0}\", Are you a student of BUKC? \n-Yes \n-No", name);
string ans = Console.ReadLine();
if (ans== "Yes" || ans == "yes" || ans == "YES" || ans == "y" || ans == "Y")
{
Console.WriteLine("Are you first semester student? \n-Yes \n-No");
string ans1 = Console.ReadLine();
if (ans1 == "Yes" || ans1 == "yes" || ans1 == "YES" || ans1 == "y" || ans1 == "Y")
{
Console.WriteLine("Do you belong to Software Engineering Department? \n-Yes \n-No");
string ans2 = Console.ReadLine();
if (ans2 == "Yes" || ans2 == "yes" || ans2 == "YES" || ans2 == "y" || ans2 == "Y")
{
Console.WriteLine("{0} you are allowed to enter", name);
}
else
{
Console.WriteLine("Sorry, you are not allowed to enter");
}
}
else
{
Console.WriteLine("Sorry, you are not allowed to enter");
}
}
else
{
Console.WriteLine("Sorry, you are not allowed to enter");
}
}
}
}

Task # 02
Write a c# program to check if the given year is a leap year or not (A year may be a leap year if it is evenly
divisible by 4. Years that are divisible by 100 (century years such as 1900 or 2000) cannot be leap years
unless they are also divisible by 400)).

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{
Console.Write("Enter The Year : ");
double year = Convert.ToDouble(Console.ReadLine());
if (year > 0)
{
if (year % 4 == 0)
{
Console.WriteLine("\tIt's a \"Leap Year\" ");
}
else
{
Console.WriteLine("\tIt's not a \"Leap Year\" ");
}
}
else
{
Console.WriteLine("Kindly enter The Correct Year");
}

Task # 03
Write a C# program that takes integer between 1 and 7 from user and displays the name of the weekday
using switch-case [day’s starts with Friday].

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{
int i, num;
for (i = 0; i < 1 ; i++)
{
Console.Write("Enter any number from 1 to 7 : ");
num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 1:
Console.WriteLine("FRIDAY");
break;
case 2:
Console.WriteLine("SATURDAY");
break;
case 3:
Console.WriteLine("SUNDAY");
break;
case 4:
Console.WriteLine("MONDAY");
break;
case 5:
Console.WriteLine("TUESDAY");
break;
case 6:
Console.WriteLine("WEDNESDAY");
break;
case 7:
Console.WriteLine("THURSDAY");
break;
default:
Console.WriteLine("Invalid Number");
break;
}
}
}
}
}

Task # 04
Write a c# program to print number of days in given month using switch-case.

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{
Console.Write("Enter a Month : ");
string mon = Console.ReadLine();
switch (mon)
{
case "January":
case "january":
case "JANUARY":
case "JAN":
case "Jan":
case "jan":
Console.WriteLine("January has 31 Days");
break;
case "February":
case "february":
case "FEBRUARY":
case "FEB":
case "Feb":
case "feb":
Console.WriteLine("February has 28 Days");
Console.WriteLine("February has 29 Days if the year is a leap year");
break;
case "MARCH":
case "March":
case "march":
case "MAR":
case "Mar":
case "mar":
Console.WriteLine("March has 31 Days");
break;
case "April":
case "april":
case "APRIL":
case "APR":
case "Apr":
case "apr":
Console.WriteLine("April has 30 Days");
break;
case "May":
case "MAY":
case "may":
Console.WriteLine("May has 31 Days");
break;
case "June":
case "june":
case "JUNE":
case "JUN":
case "Jun":
case "jun":
Console.WriteLine("June has 30 Days");
break;
case "July":
case "july":
case "JULY":
case "Jul":
case "jul":
Console.WriteLine("July has 31 Days");
break;
case "August":
case "august":
case "AUGUST":
case "AUG":
case "Aug":
case "aug":
Console.WriteLine("August has 31 Days");
break;
case "September":
case "september":
case "SEPTEMBER":
case "SEP":
case "Sep":
case "sep":
Console.WriteLine("September has 30 Days");
break;
case "October":
case "october":
case "OCTOBER":
case "OCT":
case "Oct":
case "oct":
Console.WriteLine("October has 31 Days");
break;
case "November":
case "november":
case "NOVEMBER":
case "NOV":
case "Nov":
case "nov":
Console.WriteLine("November has 30 Days");
break;
case "December":
case "december":
case "DECEMBER":
case "DEC":
case "Dec":
case "dec":
Console.WriteLine("December has 31 Days");
break;
default:
Console.WriteLine("Please Enter The Correct Month");
break;
}
}
}
}

Task # 05
Write a c# program to check if given triangle is equilateral, isosceles or scalene.

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{
double a, b, c;
Console.Write("Enter The Value of 1st Side of Triangle: \na = ");
a = Convert.ToDouble(Console.ReadLine());

Console.Write("\nEnter The Value of 2nd Side of Triangle: \nb = ");


b = Convert.ToDouble(Console.ReadLine());

Console.Write("\nEnter The Value of 3rd Side of Triangle: \nc= ");


c = Convert.ToDouble(Console.ReadLine());

if (a == b && a == c)
{
Console.WriteLine("\nThis is an \"Equilateral Triangle\" ");
}
else if(a == b || a == c || c == b)
{
Console.WriteLine("\nThis is an \"Isosceles Triangle\" ");
}
else if(a != b && b != c && c != a)
{
Console.WriteLine("\nThis is a \"Scalene Triangle\" ");
}
else
{
Console.WriteLine("\nInvalid Shape");
}
}
}
}

Task # 06
6. Write a C# program for each condition given below:

a) x > y > z

b) x and y are both less than 0

c) neither x nor y is less than 0

d) x is equal to y but not equal to z

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{
int x, y, z;
Console.Write("Enter value of x: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter value of y: ");
y = int.Parse(Console.ReadLine());
Console.Write("Enter value of z: ");
z = int.Parse(Console.ReadLine());
if (x > y && y > z)
{
Console.WriteLine("\nx > y > z");
}
if (x < 0 && y < 0)
{
Console.WriteLine("\nx and y are both less than 0");
}
if (x > 0 && y > 0)
{
Console.WriteLine("\nneither x nor y is less than 0");
}
if (x == y && x != z)
{
Console.WriteLine("\nx is equal to y but not equal to z.");
}

}
}
}
Task # 07
Write a c# program to calculate discount for a departmental store. The departmental store has two types of customers:
1) Walk-in customers 2) Registered customers. For registered customers, they are offering 5% discount if their monthly
transaction is more than Rs.100000 and 5.5% discount if their monthly transaction is more than Rs.200000, otherwise
they will get a discount of 3.5%. For Walk-in customers a 2% discount is available if the transaction amount is more than
50,000.

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{ string ans;
double trans, trans1, discount;

Console.WriteLine("|-------Discount For A Departmental Store--------|");


Console.WriteLine("|1)Registreed customer\t\t\t\t |");
Console.WriteLine("|2)Walk in customer \t\t\t\t |");
Console.Write("Enter no 1 or 2 : ");
ans = Console.ReadLine();

if (ans == "1")
{
Console.Write("Enter your monthly transaction amount : ");
trans = double.Parse(Console.ReadLine());
Console.Clear();
if (trans >= 100000 && trans < 200000)
{
discount = trans * 0.05;

Console.WriteLine("-----------------------------------------");
Console.WriteLine("Transaction amount | {0} ", trans);
Console.WriteLine("Discount | {0} ", discount);
Console.WriteLine("-----------------------------------------")
Console.WriteLine("You will get 5% Discount ");

}
else if(trans >= 200000)
{
discount = trans * 0.055;

Console.WriteLine("-----------------------------------------");
Console.WriteLine("Transaction amount | {0} ", trans);
Console.WriteLine("Discount | {0} ", discount);
Console.WriteLine("-----------------------------------------");
Console.WriteLine("You will get 5.5% Discount ");

}
else if(trans < 100000)
{

discount = trans * 0.035;

Console.WriteLine("-----------------------------------------");
Console.WriteLine("Transaction amount | {0} ", trans);
Console.WriteLine("Discount | {0} ", discount);
Console.WriteLine("-----------------------------------------");
Console.WriteLine("You will get 3.5% Discount ");
}
}

else if(ans == "2")


{
Console.WriteLine("Enter your monthly transaction amount ");
trans1 = double.Parse(Console.ReadLine());
if (trans1 >= 50000)
{
discount = trans1 * 0.02;

Console.WriteLine("-----------------------------------------");
Console.WriteLine("Transaction amount | {0} ", trans1);
Console.WriteLine("Discount | {0} ", discount);
Console.WriteLine("-----------------------------------------");
Console.WriteLine("You will get 2% discount");
}
else
{
Console.WriteLine("Need To pay {0}", trans1);
}
}
else
{
Console.WriteLine("Invalid Number ");
}

}
}
Task # 08
Write a c# program to calculate the total fee of a student of Bahria University (@ Rs.5000 per credit hour).
There is a 50% discount for students from a naval background, a 20% discount for students with a sibling
already studying in Bahria University and a 30% discount for Bahria University permanent employees.

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{ string st;
double discount;
Console.Write("Enter Your Name : ");
string name = Console.ReadLine();
Console.Write("Enter Father's Name : ");
string fname = Console.ReadLine();
Console.Write("Enter Your CNIC : ");
string cnic = Console.ReadLine();
Console.Write("Enter Department : ");
string dep = Console.ReadLine();
Console.Write("Enter Your Enrollment Number : ");
string enroll = Console.ReadLine();
Console.Write("Enter Credit Hours Of Current Semester : ");
double credit = Convert.ToDouble(Console.ReadLine());
Console.Clear();
double fee = credit * 5000;
Console.WriteLine("-----------------------------------------------");
Console.WriteLine("-Select Any Option:");
Console.WriteLine("1) Naval Background ");
Console.WriteLine("2) Siblings Already Studing");
Console.WriteLine("3) BU Permanent Employees ");
int num = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("-----------------------------------------------");
if (num == 1)
{
Console.WriteLine("You Will Get 50% Discount");
discount = fee * 0.50;
st = Convert.ToString("NAVAL");
}
else if(num == 2)
{
Console.WriteLine("You Will Get 20% Discount");
discount = fee * 0.20;
st = Convert.ToString("SIBLING ALREADY STUDYING");
}
else if(num == 3)
{
Console.WriteLine("You Will Get 30% Discount");
discount = fee * 0.30;
st = Convert.ToString("BU EMPLOYEE");
}

else
{
Console.WriteLine("Sorry! You have enter a Wrong Number");
st = Convert.ToString("");
discount = 0;
}
int disfee = Convert.ToInt32(fee - discount);

Console.Clear();
Console.WriteLine("\n\t\t****************\"FEE VOUCHER\"**************");
Console.WriteLine("\t\tStudent Name : {0}", name);
Console.WriteLine("\t\tFather's Name : {0}", fname);
Console.WriteLine("\t\tDepartment : {0}", dep);
Console.WriteLine("\t\t Background : {0}", st);
Console.WriteLine("\t\tCredit Hours : {0}\n", credit);
Console.WriteLine("\t\tTotal Fees : {0:c}", fee);
Console.WriteLine("\t\tDiscount : {0:c}", discount);
Console.WriteLine("\t\tFees After discount : {0:c}", disfee);
Console.WriteLine("\n\t\t THANK YOU ");

Console.WriteLine("\n\t\t********************************************");

}
}
}

Task # 09
Write a c# program to calculate the total hospital bill for tests performed. When a discount of 50% is offered
for community members, 30% for the needy and 20% for employees of the hospital.

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{ string name, pat;

Console.WriteLine("-------------\"ANMOL'S HOSPITAL\"-------------");
Console.Write("Enter Patient Name : ");
name = Console.ReadLine();
double bill, discount, payable;

Console.Write("Enter The Price Of Your Test:");


bill = double.Parse(Console.ReadLine());
Console.WriteLine("----------------------------------------------");
Console.Clear();

Console.WriteLine("\tPLease Select Category ");


Console.WriteLine("\t1.Community Member ");
Console.WriteLine("\t2.Needy ");
Console.WriteLine("\t3.Employee of the Hospital");
Console.WriteLine("\t4.Others");

Console.Write("\tEnter category number: ");


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

Console.Clear();
if (num == 1)

{
Console.WriteLine("You Will Get 50% Discount");
discount = bill * 0.50;
pat = Convert.ToString("Community Member");
}
else if(num == 2)
{
Console.WriteLine("You Will Get 30% Discount");
discount = bill * 0.30;
pat = Convert.ToString("Needy");
}
else if(num == 3)
{
Console.WriteLine("You Will Get 20% Discount");
discount = bill * 0.20;
pat = Convert.ToString("Hospital Employee");
}
else if(num == 4)
{
Console.WriteLine("There is No Discount for Others");
discount = 0;
pat = Convert.ToString("Others");
}
else
{
Console.WriteLine("You Have Inputted a Wrong Number");
pat = Convert.ToString("");
discount = 0;
}

Console.Clear();
Console.WriteLine("\n\t*************** TOTAL BILL ***************");
Console.WriteLine("\tPatient Name = {0}", name);
Console.WriteLine("\tTotal Bill = {0:c}", bill);
Console.WriteLine("\tDiscount = {0:c}", discount);
payable = (bill - discount);
Console.WriteLine("\tAmount Paid = {0:c}", payable);
Console.WriteLine("\n\t\t\tTHANK YOU");
Console.WriteLine("\n\t******************************************");

}
}
}

Task # 10
Suppose gpa is a variable containing the grade point average of a student. Suppose the goal of a program is to let a
student know if he/she made the Dean's list (the gpa must be 3.5 or above). Write an if... else... statement that prints
out the appropriate message (either "Congratulations—you made the Dean's List" or "Sorry you didn't make the Dean's
List")..

Solution:
using System;

namespace CP_theory_task01
{
classProgram
{
staticvoid Main(string[] args)
{ string name;
double gpa;
Console.Write("Enter your name: ");
name = Console.ReadLine();
Console.Write("Enter your semester GPA: ");
gpa = double.Parse(Console.ReadLine());
if (gpa >= 3.5)

{
Console.WriteLine("\nCongratulations! \"{0}\",You made the Dean's List", name);
}
else
{
Console.WriteLine("\nSorry! \"{0}\", you didn't make the Dean's List", name);

}
}
}
}

You might also like