Homework: Csc1043Introduction To Programming Group: Monday Submitted By: Name ID#
Homework: Csc1043Introduction To Programming Group: Monday Submitted By: Name ID#
CSC1043INTRODUCTION TO PROGRAMMING
Group: Monday
Submitted by:
Name ID#
Abdikader Shukri Muhumad 102120498
Abrar Hussain 102120663
Muhammad Shahid 102120665
Guleid Ibrahim Yusuf 102120570
Mursal Mohamed Jama 102120572
Submitted to:
Dr.Muhammad Ikhwan Jambak
25
th
November, 2013
Homework 2013
1 | P a g e
Question 1:
ATM Source code: Using Looping
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1_LOOP___ATM
{
class Program
{
static void Main(string[] args)
{
//declare variables
string pinNumber = "1234";
double creditBalance = 2000;
string accountNumber = "08-02-2000";
string accountHolder = "Omer";
string inputPin;
uint amountWithdraw, amountDeposit;
int userOption;
bool doLoop = true;
//change the color
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
do
{
//request the users to key in their pin
Console.WriteLine("please enter your pin");
inputPin = Console.ReadLine();
//compare the user PIN input with the PIN number
if (pinNumber != inputPin)
{
Console.WriteLine("incorrect PIN");
}
else
{
Console.Clear();
Console.WriteLine("Welcome" + accountHolder);
Console.WriteLine("your account number is" + accountNumber);
Console.WriteLine("your current balance is" + creditBalance);
//ask the user to choose 1 for withdraw and 2 for deposit
Console.WriteLine("please choose 1 for withdraw and 2 for
deposit");
userOption = int.Parse(Console.ReadLine());
if (userOption == 1)
{
//process the withdraw
Console.WriteLine("please enter the withdraw amount");
amountWithdraw = uint.Parse(Console.ReadLine());
if (amountWithdraw > creditBalance)
{
Console.WriteLine("Insuficient amount request");
}
else
{
Homework 2013
2 | P a g e
//calculate the balance
//this satement is not a C# convention
//creditBalance = creditBalance - amount withdraw;
//this is the C# convention
creditBalance -= amountWithdraw;
Console.WriteLine("you made a withdraw of ${0} to your
account number {1} and your new balance is ${2}", amountWithdraw, accountNumber,
creditBalance);
}
//print receipt
}
else if (userOption == 2)
{
//process the deposit
Console.WriteLine("please enter the deposit amount");
amountDeposit = uint.Parse(Console.ReadLine());
//calculate the balance
//this satement is not a C# convention
//creditBalance = creditBalance + amountDeposit;
//this is the C# convention
creditBalance += amountDeposit;
//print the receipt
Console.WriteLine("you made a deposit of ${0} to your account
number {1} and your new balance is ${2}", amountDeposit, accountNumber,
creditBalance);
}
else if (userOption != 1 && userOption != 2)
{
//wrong input
Console.WriteLine("wrong input");
}
}
Console.ReadKey();
} while (doLoop);
}
}
}
Homework 2013
3 | P a g e
Question 2:
Assignment Part C: Using Arrays
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1_ARRAY_PART_C
{
class Program
{
static void Main(string[] args)
{
//Declare arrays
string[] acaType = { "prof", "lec", "lab" };
double[] acaSalary = { 6000, 4000, 2000 };
string[] adminType = { "Headofdept", "sec", "clerk" };
double[] adminSalary = { 4000, 2000, 1000 };
const int housingAllowance = 3000;
//Declare all the variables
int
basicSalary,
bonus = 0,
teachingAllowance = 0,
individualBonus = 0,
userChoice,
rank,
yearService,
totalSalary = 0;
string employeeId;
Console.WriteLine("Please type in your ID.");
employeeId = Console.ReadLine();
Homework 2013
4 | P a g e
Console.WriteLine("Please type in 1 for Academician and 2 for
Administrator.");
userChoice = int.Parse(Console.ReadLine());
switch (userChoice)
{
case 1:
Console.WriteLine("Your employment type is Academician.");
teachingAllowance = 2000;
Console.WriteLine("Please enter your rank 1 for Professor, 2 for
Lecturer and 3 for Laborant.");
rank = int.Parse(Console.ReadLine());
basicSalary = (int)acaSalary[rank-1];
Console.WriteLine("How many years have you been in service?");
yearService = int.Parse(Console.ReadLine());
if (yearService > 3)
{
bonus = basicSalary;
}
else if (yearService < 3)
{
bonus = (basicSalary / 2);
}
else
{
Console.WriteLine("Wrong input.");
Console.ReadLine();
Environment.Exit(0);
}
Console.WriteLine("Please type in the individual bonus.");
individualBonus = int.Parse(Console.ReadLine());
totalSalary = basicSalary + housingAllowance + teachingAllowance +
bonus + individualBonus;
Console.WriteLine("Your ID is {0}", employeeId);
Console.WriteLine("Your basic salary is RM {0}", basicSalary);
Console.WriteLine("Your housing allowance is RM {0}",
housingAllowance);
Console.WriteLine("Your teaching allowance is RM {0}",
teachingAllowance);
Console.WriteLine("Your bonus is RM {0}", bonus);
Console.WriteLine("Your individual bonus is RM {0}",
individualBonus);
Console.WriteLine("Your total salary is RM {0}", totalSalary);
Console.ReadLine();
break;
case 2:
Console.WriteLine("Your employment type is Administrator.");
Console.WriteLine("Please enter your rank 1 for Head of
Department, 2 for Secretary and 3 for Clerck.");
rank = int.Parse(Console.ReadLine());
Homework 2013
5 | P a g e
basicSalary = (int)adminSalary[rank-1];
Console.WriteLine("How many years have you been in service?");
yearService = int.Parse(Console.ReadLine());
if (yearService > 3)
{
bonus = basicSalary;
}
else if (yearService < 3)
{
bonus = (basicSalary / 2);
}
else
{
Console.WriteLine("Wrong input.");
Console.ReadLine();
Environment.Exit(0);
}
Console.WriteLine("Please type in the individual bonus.");
individualBonus = int.Parse(Console.ReadLine());
totalSalary = basicSalary + housingAllowance + bonus +
individualBonus;
Console.WriteLine("Your ID is {0}", employeeId);
Console.WriteLine("Your basic salary is RM {0}", basicSalary);
Console.WriteLine("Your housing allowance is RM {0}",
housingAllowance);
Console.WriteLine("Your teaching allowance is RM {0}",
teachingAllowance);
Console.WriteLine("Your bonus is RM {0}", bonus);
Console.WriteLine("Your individual bonus is RM {0}",
individualBonus);
Console.WriteLine("Your total salary is RM {0}", totalSalary);
Console.ReadLine();
break;
}
}
}
}
Homework 2013
6 | P a g e