Professional Documents
Culture Documents
BSME-MECH-2 METE280 - P1
WEEK 2A EXERCISES:
Basic Elements in C#
Problem 1: Write a program that accept an integer representing the total number of seconds
and output the equivalent time in hours, minutes, and seconds.
using System;
namespace Exercise1
{
class Program
{
static void Main(string[] args)
{
int hour, min, sec, input;
Console.ReadLine();
}
}
}
Problem 2: Write a program that will solve the problem below: Chififay was promised by her
employer a 10% raise for the month. If her salary is P700 per month, how much will she receive
the next month if she gets cash advance of P500 and promise to pay it the next month?
using System;
namespace Exercise2a2_MonthlyPay
{
class Program
{
static void Main(string[] args)
{
int pay = 700;
double total = 0;
Console.ReadKey();
}
}
}
Problem 3: Write a program that extracts and prints the second rightmost digit of the integral
portion of a float.
using System;
namespace Exercise2a3_Second_Digit
{
class Program
{
static void Main(string[] args)
{
float num;
int place2;
Console.ReadKey();
}
}
}
WEEK 2B EXERCISES:
Conditional Control Structure
Problem 1:
A company selling household appliances gives commissions to its salesman determined by the
kind of product sold as well as the sales amount.
Type 1: 7% of sale or 400, whichever is more.
Type 2: 10% of sale or 900, whichever is less.
Type 3: 12% of sale.
Type 4: P250, regardless of sale price.
Make a program that would input the KIND of appliance sold (between 1-4) and the sale PRICE
(a positive floating-point value), and output the Commission that the salesman will receive.
using System;
namespace Exercise2b1_Commission
{
class Program
{
static void Main(string[] args)
{
int type;
double sale, com = 0, totalcom = 0;
if (type == 1)
{
com = sale * 0.07;
if (com > 400)
{
totalcom = com;
}
else
{
totalcom = 400.00;
}
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else if (type == 2)
{
com = sale * 0.1;
if (com < 900)
{
totalcom = com;
}
else
{
totalcom = 900.00;
}
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else if (type == 3)
{
totalcom = sale * .12;
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else if (type == 4)
{
totalcom = 250.00;
Console.WriteLine("\nTotal Commission is {0:0.00}", totalcom);
}
else
{
Console.WriteLine("Wrong input!");
}
Console.ReadKey();
}
}
}
Problem 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise2b2_DeepQuest
{
class Program
{
static void Main(string[] args)
{
int region, timecode;
double min, totsec, sec, charge = 0, total = 0;
if (timecode == 1)
{
switch (region)
{
case 1: charge = total * 18.74; break;
case 2: charge = total * 21.36; break;
case 3: charge = ((double)total / 3) * 68.42; break;
case 4: charge = total * 20.61; break;
case 5: charge = total * 21.22; break;
case 6: charge = ((double)total / 3) * 59.65; break;
case 7: charge = ((double)total / 4) * 87.38; break;
default: Console.WriteLine("Wrong region code input"); break;
}
}
else if (timecode == 2)
{
switch (region)
{
case 1: charge = total * 14.35; break;
case 2: charge = total * 19.41; break;
case 3: charge = ((double)total / 3) * 65.25; break;
case 4: charge = total * 18.23; break;
case 5: charge = total * 20.13; break;
case 6: charge = ((double)total / 3) * 57.32; break;
case 7: charge = ((double)total / 4) * 84.72; break;
default: Console.WriteLine("Wrong region code input"); break;
}
}
else
{
Console.WriteLine("\tWrong time code input");
}