INFO 350 – Spring 2024, Programming Assignment #4W. Chin
Redo the short answer problems from the midterm. Write it out on paper and take pictures or scan
the papers and upload to Canvas. I suggest that you familiarize yourself with the programming
concepts we have covered and try to simulate exam conditions.
Short Answer #1 (15 Points): What is the output?
NOTE: I suggest to create a table that has each variable and what the result is at the end of
each line of execution.
static void Main(string[] args)
{
int a=0, b=0, c=0, d=0, e=0;
a = 1;
b = a + 1;
c = 3 + a;
d += b;
a = a + 2 – c++;
Console.WriteLine(“a = ” + a);
Console.WriteLine(“c = ” + c);
e = b– + 1;
a = a + 2 – c++;
c = a * 2 / b + 2;
a = d++ % b;
}
Console.WriteLine(“b = ” + b);
Console.WriteLine(“d = ” + d);
Console.WriteLine(“e = ” + e);
1
INFO 350 – Spring 2024, Programming Assignment #4
W. Chin
Short Answer #2 (15 Points): Given the following, write the code to calculate the average age
such that the array can be modified and the output would still be correct.
using System;
namespace MyApp
{
internal class Program
{
static void Main(string[] args)
{
int[] givenAge = { 10, 33, 25, 53 };
int givenAgesCount = 4;
double averageAge;
}
}
}
Console.WriteLine(“Average age is ” + averageAge);
2
INFO 350 – Spring 2024, Programming Assignment #4
W. Chin
Short Answer #3 (15 Points): Given the following, write the code to calculate the average price
of the widgets sold for a price more than the priceCutOff given. Widgets that were sold for less
than or equal to the priceCutOff are not part of the average.
using System;
namespace MyApp
{
internal class Program
{
static void Main(string[] args)
{
double[] widgetsSoldPrice = { 50.29, 495.2, 599.95, 295.42, 9985.00 };
int widgetsSoldCount = 5;
const double priceCutOff = 450.55;
double averagePrice;
double sumPrices = 0.0;
int numberOfWidgetsForCutOff = 0;
int index;
Console.WriteLine(“Average price of widgets priced > “ + priceCutOff +
“ was: ” + averagePrice);
}
}
}
3
INFO 350 – Spring 2024, Programming Assignment #4
W. Chin
Short Answer #4 (15 Points): Given the following, write the code that calls a method that
calculates the taxes owed. The tax rate for income below or equal to $50,000 is 5% and the tax
rate for the income above $50,000 is 20%. Calculate the taxes owed after accounting for the
taxes already paid.
namespace MyApp
{
internal class Program
{
static void Main(string[] args)
{
double income = 72593;
double taxesPaid = 2943;
double taxesOwed;
Console.WriteLine(“Tax owed is ” + taxesOwed);
}
static
{
}
}
}
4
INFO 350: Chin
Program #5
Change
Write a program in C# that creates a custom Person class with constructor that can hold the
following the properties of: , , , ,
, , , , and .
Create a method that prints a shipping label, with Name on one line, address on the next, and no
email address.
Create a Customer subclass of Person that has the additional properties of
using a DateTime class. Implement a method that property calculates the number of years a
customer has been a customer, taking into account the current month and day. You can create a
new DateTime object for this task in this manner:
DateTime joinDate = new DateTime(2014, 9, 23);
In your main method, create a List of 6 people that you populate with data of your
choice. Use foreach loop to print out the shipping labels of everyone on the list.
Then create 4 instances of Customer, again with your own data, and then use foreach to print out
each customer and how long they have been a customer in years. Make sure that each output is a
different. Then loop through each Customer and print out the two customers that have joined the
earliest.