Objectives and Grading Lab Objectives: To be able to design program logic using
ID: 3636605 • Letter: O
Question
Objectives and GradingLab Objectives:
To be able to design program logic using either a flowchart or pseudocode
To be able to define and use data types
To be able to prompt the user for input
To be able to use the assignment statement for calculations
To be able to display output to the console in a formatted manner
To be able to debug a program of syntax and logic errors
To be able to make decisions
Your lab grade will be based upon:
the formatting of your source code;
the use of meaningful identifiers;
the extent of internal documentation; and
the degree to which an exercise's specifications are met.
Preparation:
If you are using the Citrix remote lab, follow the login instructions located in the iLab tab in Course Home.
iLab 2
Part A: Calculate Shipping Charge
Requirements
Your mission: Write a program that gets the amount of a purchase from the user and then calculates the shipping charge, based on the following table:
$0.00 - $250.00: $5.00
$250.01 - $500.00: $8.00
$500.01 - $1,000.00: $10.00
$1,000.01 - $5,000.00: $15.00
over $5,000.00: $20.00
Sample output from program:
Enter a purchase amount to find out your shipping charges.
Please enter the amount of your purchase: 234.65
The shipping charge on a purchase of $234.65 is $5.00.
Press any key to continue . . .
Tips
Best practice: Put yourself in the place of the program. What questions would you ask a customer in order to get the best input? How would you determine the correct shipping charges if you had to make the decisions yourself? Write out the questions you would ask yourself on paper as pseudocode and/or in Visual Studio as C# comments, and then implement them one by one, testing as you go. Remember to not write too much at one time. Always add and test functionality incrementally!
You can use the pseudocode below as a guide:
Prompt the user for the sale amount
Is sale amount greater than $5,000.00?
If so, shipping is $20.00
If not, is sale amount greater than $1,000.00?
If so, shipping is $15.00
If not, is sale amount greater than $500.00?
If so, shipping is $10.00
If not, is sale amount greater than $250.00?
If so, shipping is $8.00
If not, is sale amount greater than $0.00
shipping is $5.00
If not
shipping is $0.00
If shipping is $0.00
Display "Error incorrect input"
If not
Display sale amount and shipping charge
Part B: TV Channel to Call Sign
Requirements
Your mission: Write a program that translates a TV channel (1 through 10) in your area to its respective call sign. For example, in the New York metropolitan area, channel 2 translates to WCBS. If a channel is unused in your area, tell the user that this is the case.
Sample output from program:
Translate TV Channel Number to Call Sign
Enter channel number: 1
Channel 1 is undesignated in your area
Enter channel number: 2
Call sign for channel 2 is WCBS
Enter channel number: 6
Call sign for channel 6 is WRNNDT
Tips
Best practice: Put yourself in the place of the program. What steps would you personally need to perform in order to process a channel translation yourself? Write out those steps on paper as pseudocode and/or in Visual Studio as C# comments, and then implement them one by one, testing as you go. Remember to not write too much at one time. Always add and test functionality incrementally!
Pseudocode: Although there are several valid ways to write the program, the following is an outline of one way to design the overall logic.
Declare variables for channel and call sign
Get channel number from user
Use appropriate decision structure to translate number to call sign
If number is valid in area
Print out translation
If not
Tell user this is the case
Explanation / Answer
PART A:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace shipping
{
class Program
{
static void Main(string[] args)
{
double saleAmount = 0;
double shipping = 0;
Console.Write("Enter a purchase amount to find out your shipping charges: ");
string line = Console.ReadLine();
saleAmount = double.Parse(line);
if (saleAmount > 5000) shipping = 20;
else if (saleAmount > 1000) shipping = 15.00;
else if (saleAmount > 500) shipping = 10.00;
else if (saleAmount > 250) shipping = 8.00;
else shipping = 5.00;
Console.WriteLine(String.Format("The shipping charge on a purchase of ${0:f2} is ${1:f2}", saleAmount, shipping));
Console.Write("Press any key to exit...");
Console.ReadKey(false);
}
}
}
PART B:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ChannelProgram
{
class Program
{
static void Main(string[] args)
{
int channel;//to store channel number
String callSign="";
Boolean available = true;
for (int i = 1; i <= 10; i++)
{
Console.Write(" Enter Channel Number : ");
channel = Convert.ToInt32(Console.ReadLine());
switch (channel)
{
case 1: available = false;/*Making
available as false*/
break;
case 2: callSign="WCBS";
break;
case 3: callSign="WSTM";
break;
case 4: callSign="WNBC";
break;
case 5: callSign="WNYW";
break;
case 6: callSign ="WRGB";
break;
case 7: callSign="WABC";
break;
case 8: callSign="WROC";
break;
case 9: callSign="WWOR";
break;
case 10: callSign="WHEC";
break;
}//End of switch
if (available)
Console.WriteLine("Call sign for channel {0} is
{1}", channel, callSign);
else
Console.WriteLine("Channel {0} is undesignated
in your area", channel);
available = true;
}//End of for loop
/*To pause the output until user press any key*/
Console.Read();
}//End of main
}//End of class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.