Você está na página 1de 10

IME-279

Arsalan Akram

CSP

using System;

namespace _5._17
{
public class AutoMobileTest
{
public static void Main(string[] args)
{

AutoMobile myAutoMobile = new AutoMobile();

myAutoMobile.GasMilage();

public class AutoMobile


{
public void GasMilage()
{
int miles, gallons, totalMiles=0, totalGallons=0, tankfulCounter=0;
char loop = 'c';
//input for gallons and miles
Console.Write("Enter the gallons tankful :");
gallons = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the miles :");
miles = Convert.ToInt32(Console.ReadLine());
while (loop != 'q')
{
totalMiles = totalMiles + miles;
totalGallons = totalGallons + gallons;
tankfulCounter = tankfulCounter + 1;

//display result
Console.WriteLine("\nMiles per gallon this time :{0:F2}", (double)miles/gallons);
Console.WriteLine("Average miles per gallon so far :{0:F2}", (double)totalMiles/totalGallons);
Console.WriteLine("No. of Tankfuls so far : {0}\n", tankfulCounter);
//to quit or not
Console.WriteLine("Any key to continue \t q to exit \n");
ConsoleKeyInfo key = Console.ReadKey();
loop = key.KeyChar;

//input for gallons and miles


Console.Write("Enter the gallons tankful:");
gallons = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the miles :");
miles = Convert.ToInt32(Console.ReadLine());

IME-279

Arsalan Akram

CSP

IME-279

Arsalan Akram

using System;

namespace _5._18
{
class Account
{
static void Main(string[] args)
{
int data = 0;

while (data != -1)


{
//get account number
Console.Write("Enter an account number, enter -1 to quit: ");
data = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
if (data != -1)
{
ExistingCustomer newCustomer = new ExistingCustomer();
newCustomer.Customer(data); //pass 'data' to object
}
}

public class ExistingCustomer


{
public void Customer(int number) // get value from Main
{
// initializing
int accountNumber = number;
int balance, charges, credits, creditLimit;

//get input
Console.Write("Enter Starting balance: Rs");
balance = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter total charges by the customer : Rs");
charges = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter total credits applied to the customers account : Rs");
credits = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the customer credit limit : Rs");
creditLimit = Convert.ToInt32(Console.ReadLine());

//balance
balance = balance + charges - credits;
Console.WriteLine("\nThe new balance in your Acount No. {1} is Rs{0}\n",
balance,accountNumber);

//Credit limit check


if (balance > creditLimit)
{
Console.WriteLine("Credit limit exceeded!");
}

CSP

IME-279

Arsalan Akram

using System;

namespace _5._19
{
class Earnings
{
static void Main(string[] args)
{
//Intialization
int item = -1, quantity=0, total = 0;
double sum = 0;

Console.WriteLine("Item\t Value");
Console.WriteLine("1-\tRs239.99\n2-\tRs129.75\n3-\tRs99.95\n4-\tRs350.89");
//Getting inputs and Processing
while (item != 0)
{
Console.WriteLine("Enter Serial of Item Sold (Enter 0 to end): ");
item = Convert.ToInt32(Console.ReadLine());
if (item != 0)
{
Console.WriteLine("Enter quantity of sold item");
quantity = Convert.ToInt32(Console.ReadLine());
}

switch (item)
{
case 1: sum +=
case 2: sum +=
case 3: sum +=
case 4: sum +=
}
total += quantity;

239.99
129.75
099.95
350.89

*
*
*
*

quantity;
quantity;
quantity;
quantity;

break;
break;
break;
break;

double earning = 200 + .09 * sum; //Earning formula

//Display Result
Console.WriteLine("No. of Item Sold : {0}", total);
Console.WriteLine("Sum of Prices of items : Rs {0}", sum);
Console.WriteLine("Total Earnings : Rs {0:F2}", earning);

Console.ReadLine();

CSP

IME-279

Arsalan Akram

using System;

namespace _5._20
{
class SalaryCalculator
{
static void Main()
{
int total;
Console.WriteLine("Enter no. of Emplyees");
total = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= total; i++)
{
Employee employee = new Employee();
employee.data(i);
employee.pay(i);
}
Console.ReadLine();

}
class Employee
{
public int hours, payrate, ExHours;
public double Pay, ExPay;
public void data(int num)
{
Console.Write("No. of hours worked by Employee {0} : ", num);
hours = Convert.ToInt32(Console.ReadLine());
Console.Write("Pay for each hour : Rs");
payrate = Convert.ToInt32(Console.ReadLine());
}

public void pay(int num)


{
if (hours > 40)
{
ExHours = hours - 40;
ExPay = ExHours * payrate * 1.5;
Pay = 40 * payrate + ExPay;
}
else if (hours < 40)
{
Pay = hours * payrate;
}
Console.WriteLine("Gross pay of Employee{0} is Rs{1} \n", num, Pay);
}

CSP

IME-279

Arsalan Akram

using System;

namespace _6._16
{
class BarChart
{
static void Main(string[] args)
{
int[] num = new int[3];
Console.WriteLine("Enter three numbers ranging 1 - 30 ");
num[0] = Convert.ToInt32(Console.ReadLine());
num[1] = Convert.ToInt32(Console.ReadLine());
num[2] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n Bar Chart \n");
for (int i = 0; i < num[0]; i++)
{ Console.Write("*"); }
Console.WriteLine();
for (int i = 0; i < num[1]; i++)
{ Console.Write("*"); }
Console.WriteLine();
for (int i = 0; i < num[2]; i++)
{ Console.Write("*"); }
Console.WriteLine();

Console.ReadLine();

CSP

IME-279

Arsalan Akram

using System;

namespace _5._21
{
class LargestNum
{
static void Main(string[] args)
{
int counter,number,num, largest=0;

//Number of integers
Console.WriteLine("Total No. of integers : ");
counter = Convert.ToInt32(Console.ReadLine());

//processing input
Console.Write("Enter Integer No. 1 : ");
num = Convert.ToInt32(Console.ReadLine());
for (int i = 2; i < counter; i++)
{
Console.Write("Enter Integer No. {0} : ", i);
number = Convert.ToInt32(Console.ReadLine());
if (number > num) largest = number;
num = number;
}
//Display result
Console.WriteLine("Largest number is {0}", largest);
Console.ReadLine();

CSP

IME-279

Arsalan Akram

CSP

using System;

namespace _6._17
{
class Sales
{
static void Main(string[] args)
{
int item = -1, qty = 0;
double sum = 0, retail;
Console.WriteLine(" Item \t\t Value");
Console.WriteLine(" Product 1\t $2.98\n Product 2 \t $4.50\n Product 3 \t $9.98\n");
while (item != 0)
{
Console.WriteLine("Enter the Serial and Quantity of Product (Enter 0 to quit)");
item = Convert.ToInt32(Console.ReadLine());
if (item != 0) qty = Convert.ToInt32(Console.ReadLine());
switch (item)
{
case 1:
retail = 2.98 * qty;
sum += retail;
Console.WriteLine("Product 1 X {0} = {1}", qty, retail); break;
case 2:
retail = 4.50 * qty;
sum += retail;
Console.WriteLine("Product 1 X {0} = {1}", qty, retail); break;
case 3:
retail = 9.98 * qty;
sum += retail;
Console.WriteLine("Product 1 X {0} = {1}", qty, retail); break;
}

}
Console.WriteLine("\nTotal Price is $" + sum);

Console.ReadLine();

IME-279

Arsalan Akram

CSP

using System;

namespace _6._20
{
class PieValue
{
static void Main(string[] args)
{
decimal pie;
int j = 1;//terms - 1
pie = 4;
for (decimal i = 3; i < 1000; i += 2)
{
if (j % 2 == 0) pie += (4 / i);
else pie -= (4 / i);

Console.WriteLine("{0} terms \t\t Pie =


j++;

}
Console.ReadLine();

{1}", j + 1, pie);

IME-279

Arsalan Akram

using System;

namespace _6._21
{
class Program
{
static void Main(string[] args)
{
for(int i=1;i < 500; i++)
{
for(int j=1; j < 500; j++)
{
for(int k=1; k < 500; k++)
{
if((int)Math.Pow(i, 2) + (int)Math.Pow(j, 2) == (int)Math.Pow(k, 2))
{ Console.WriteLine("{0},{1},{2}", i, j, k); }
}
}
}
Console.ReadLine();
}
}
}

10

CSP

Você também pode gostar