You are on page 1of 14

# ASSIGNMENT 3

PROGRAMMING
FUNDAMENTALS
COURSE ID: 90962
STUDENT ID: 7663

## QUESTION 1: At Imtiaz Super Store, while purchasing certain items,

customer gets a discount of 10% only if the quantity of purchased items is
more than Rs. 5000. If quantity and price per item are input through the
keyboard, write a program to calculate the total bill.

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question1
{
class Program
{
static void Main(string[] args)
{
int quantity;
double unit, bill;
Console.Write("Enter the unit price of the item: ");
Console.Write("Enter the quantity of the item purchased: ");
bill = quantity * unit;
Console.WriteLine("The bill is {0}", bill);
if (bill > 5000)
{
bill = (bill / 100) * 10;
Console.WriteLine("The discounted bill is {0}", bill);
}
}
}

## Question 02: In a company an employee is paid as under:

If his basic salary is less than Rs. 15,000, then Home Rental Allowance = 10% of
basic salary and Dining Allowance = 90% of basic salary. If his salary is either equal
to or above Rs. 15,000 but less than Rs. 20,000 then Home Rental Allowance = Rs.
500 and Dining Allowance = 98% of basic salary. If the employees salary is input
through the keyboard write a program to find his gross salary.
Gross Salary = Basic Salary + Home Rental Allowance + Dining Allowance

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question2
{
class Program
{
static void Main(string[] args)
{
double basic, gross, homeAllowance, diningAllowance;
if (basic < 15000)
{
homeAllowance = (basic / 100) * 10;
diningAllowance = (basic / 100) * 90;
gross = basic + homeAllowance + diningAllowance;
Console.WriteLine("Your Home Rental Allowance is {0}", homeAllowance);
Console.WriteLine("Your Dining Allowance is {0}", diningAllowance);
Console.WriteLine("The gross salary is {0}", gross);
}
else if (basic >= 15000 && basic < 20000)
{
homeAllowance = 500;
diningAllowance = (basic / 100) * 98;
gross = basic + homeAllowance + diningAllowance;
Console.WriteLine("Your Home Rental Allowance is {0}", homeAllowance);
Console.WriteLine("Your Dining Allowance is {0}", diningAllowance);
Console.WriteLine("The gross salary is {0}", gross);
}
}
}
}

Question 03: Team Nascent Innovations is a software house that insures its
software developers in the following cases:

## If the software developer is married.

If the software developer is unmarried, male & above 28 years of age.
If the software developer is unmarried, female & above 22 years of
age.
In all other cases, the software developer is not insured. If he marital status, gender
and age of the software developer are user defined, write a program to determine
whether the software developer is to be insured or not.

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question3
{
class Program
{
static void Main(string[] args)
{
int status, age;
char gender;
if (status == 1)
{
Console.WriteLine("Congratulations. You are insured.");
}
else if (gender == 'M' && age == 28)
{
Console.WriteLine("Congratulations. You are insured.");
}
else if (gender == 'F' && age == 22)
{
Console.WriteLine("Congratulations. You are insured.");
}
else
{
Console.WriteLine("Sorry. The company will not pay for your insurance.");
}

}
}

Question 04: Write a program that asks user to enter a number, your program,
then tells that is one of these: positive even, positive odd, negative even, negative
odd or its a ZERO.

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question4
{
class Program
{
static void Main(string[] args)
{
int number;
Console.WriteLine("\tProgram to check whether a number is even, odd, negative even
\n\t\t\tnegative odd or zero\n\n");
Console.Write("Enter the number: ");
if (number >= 1 && number % 2== 0)
{
Console.WriteLine("Positive Even.");
}
else if (number >= 1 && number %2 != 0)
{
Console.WriteLine("Positive Odd.");
}
else if (number < 0 && number %2 == 0)
{
Console.WriteLine("Negative Even.");
}
else if (number < 0 && number %2 != 0)
{
Console.WriteLine("Negative Odd.");
}
else
{
Console.WriteLine("The number is zero.");
}
}
}

Question 05: Write a program to calculate the salary as per the following table:

Gender

Male

Female

Years of Service
Greater or equals to 05
Greater or equals to 05
Less than 05

Qualification
MS or MBA
BS or MCS
BS or MCS

Salary
90,000
60,000
50,000

Less than 05
Greater or equals to 05

BBA
MS or MBA

25,000
80,000

Greater or equals to 05
Less than 05

BS or MCS
BS or MCS

55,000
40,000

Less than 05

BBA

20,000

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question5
{
class Program
{
static void Main(string[] args)
{
char gender;
string qualification;
int years;
Console.WriteLine("For MS, MCS and MBA, years of Service must always be greater or
equal to 5\n\n\n");

## if (gender=='M' && (qualification== "MS" || qualification== "MBA") && years >= 5)

{
}
else if (gender== 'M' && (qualification== "BS" || qualification == "MCS") && years >= 5)
{
}
else if (gender == 'M' && (qualification == "BS" || qualification == "MCS") && years < 5)

}
}

}
if (gender=='M' && qualification== "BBA" && years >= 5)
{
}
else if (gender=='F' && (qualification== "MS" || qualification== "MBA") && years >= 5)
{
}
if (gender=='F' && (qualification== "BS" || qualification== "MCS") && years >= 5)
{
}
else if (gender == 'F' && (qualification == "BS" || qualification == "MCS") && years < 5)
{
}
if (gender=='F' && qualification== "BBA" && years > 5)
{
}

Question 06: If cost price and selling price of an item is input through the
keyboard, write a program to that tells seller is at profit or loss? Further, it should
ask user to enter C if s/he wants to know how much profit or lost seller incurred.

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question6
{
class Program
{
static void Main(string[] args)
{
double cost, selling;
Console.Write("Please enter the cost price of the object: ");
Console.Write("Please enter the selling price of the object: ");

## if (selling > cost)

{
Console.WriteLine("\nThe seller is at profit.");
Console.WriteLine("\nPlease press C if you wish to find out how much profit incurred ");
if (choice == 'C' || choice == 'c')
{
Console.WriteLine("\nThe profit is {0}", (selling-cost));
}
}
else
{
Console.WriteLine("\nThe seller is at loss.");
Console.WriteLine("\nPlease press C if you wish to find out how much loss incurred ");
if (choice == 'C' || choice == 'c')
{
Console.WriteLine("\nThe profit is {0}", (cost-selling));
}
}

}
}

Question 07: If the ages of Alpha, Bravo and Charlie are taken as input from user,
write a program that tell who is the youngest of them.

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question7
{
class Program
{
static void Main(string[] args)
{
int alpha, bravo, charlie;
Console.Write("Enter the age of alpha: ");
Console.Write("Enter the age of bravo: ");
Console.Write("Enter the age of charlie: ");
if (alpha > bravo && alpha > charlie)
{
Console.WriteLine("Alpha is the eldest.");
}
if (bravo > alpha && bravo > charlie)
{
Console.WriteLine("Bravo is the eldest.");
}
if (charlie > alpha && charlie > bravo)
{
Console.WriteLine("Charlie is the eldest.");
}
if (alpha == bravo && alpha == charlie)
{
Console.WriteLine("They are all the same age.");
}
}
}

Question 08: Write a program that will take x and y coordinates of a point from
user. Your program has to tell whether the given point is on x-axis, y-axis or on the
origin (0,0)
SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question8
{
class Program
{
static void Main(string[] args)
{
int x_cor, y_cor;
Console.Write("Enter the x coordinate of the point: ");
Console.Write("\nEnter the y coordinate of the point: ");
if (x_cor >= 1 && y_cor == 0)
{
Console.WriteLine("\nThe point lies on x-axis");
}
if (x_cor == 0 && y_cor >= 1)
{
Console.WriteLine("\nThe point lies on y-axis");
}
if (x_cor == 0 && y_cor == 0)
{
Console.WriteLine("\nThe point lies on the origin.");
}
if (x_cor >= 1 && y_cor >= 1)
{
Console.WriteLine("\nThe point doesnt lie on x axis, y axis or origin");
}
}
}
}

Question 09: Suppose the center of the circle is at point P1 whose coordinates is x
= 19, y = -1. Now write a program that will ask user to enter radius R of circle and
coordinates of another point P2. Then your program has to tell whether the point
lies inside the circle or outside.

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question9
{
class Program
{
static void Main(string[] args)
{
double x1= 19, y1= -1;
Console.WriteLine("\n\nPlease enter the coordinates of the second circle\n");
Console.Write("\nX coordinate: ");
double x2;
double y2;
Console.Write("\nY coordinate: ");
double test = Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2);
{
Console.WriteLine("\nThe point lies inside the circle.");
}
{
Console.WriteLine("\nThe point lies outside the circle.");
}
{
}
}
}

Question 10:Pakistan Steel Mills needs to implement a program that will help their
users to find the quality of the melted iron. They have following 3 criteria:

## 1 Hardness must be greater than 50

2 Carbon content must be less than 70%
3 Tensile strength must be greater than 56000
The quality benchmarks are as follows:

## Best quality if all of above conditions are met

Good quality if conditions 1 and 2 are met
Average quality if conditions 2 and 3 are met
Fair quality if any of the conditions are met
Poor quality if none of them are met

SOURCE CODE:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Question10
{
class Program
{
static void Main(string[] args)
{
int hardness, carbon, tensile;
Console.Write("Enter the hardness of the melted iron: ");
Console.Write("Enter the carbon content of the iron: ");
Console.Write("Enter the tensile strength of the iron: ");
if (hardness > 50 && carbon < 70 && tensile > 56000)
{
Console.WriteLine("Best quality.");
}
else if (hardness > 50 && carbon < 70 && tensile < 56000)
{
Console.WriteLine("Good quality");
}
else if (hardness < 50 && carbon <70 && tensile > 56000)
{
Console.WriteLine("Average quality");
}
else if (hardness > 50 || carbon < 70 || tensile > 56000)

}
}

Console.WriteLine("Fair quality");
}
else
{
Console.WriteLine("Poor quality");
}