Thursday, September 30, 2010

First assignment Morning class

Here is the program planner

What is the main purpose of your program?
To calculate miles per gallon and cost per mile
What is the output for your program?
miles per gallon
Cost per mile

What is the input needed to get that output?
total miles (beginning and ending miles
price per gallon
total gallons

What steps are required to convert the input into the output (algorithm)?
Miles per gallon = total miles / total gallons
cost per mile= price per gallon/miles per gallon

How will you test that the output is correct?
Test it against data where you know answer

Here is the WPF form xaml:

<:Window x:Class="GasCalculator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Background="#FF8F8FE3">
<Grid>
<Label Content="Total Miles" Height="38" HorizontalAlignment="Left" Margin="21,25,0,0" Name="label1" VerticalAlignment="Top" Width="144" FontSize="18" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,33,212,0" Name="txtTotalMiles" VerticalAlignment="Top" Width="120" />
<Label Content="Price Per Gallon" FontSize="18" Height="38" HorizontalAlignment="Left" Margin="21,79,0,0" Name="label2" VerticalAlignment="Top" Width="144" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,87,212,0" Name="txtPricePerGallon" VerticalAlignment="Top" Width="120" />
<Label Content="Total Gallons" FontSize="18" Height="38" HorizontalAlignment="Left" Margin="21,123,0,0" Name="label3" VerticalAlignment="Top" Width="144" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,0,212,157" Name="txtTotalGallons" VerticalAlignment="Bottom" Width="120" />
<Button Content="Calculate" Height="29" HorizontalAlignment="Left" Margin="35,189,0,0" Name="btnCalculate" VerticalAlignment="Top" Width="75" Click="btnCalculate_Click" />
<Label Content="Label" Height="38" HorizontalAlignment="Left" Margin="162,191,0,0" Name="lblMilesPerGallon" VerticalAlignment="Top" Width="264" FontSize="18" />
<Label Content="Label" Height="33" HorizontalAlignment="Left" Margin="162,235,0,0" Name="lblCostPerMile" VerticalAlignment="Top" Width="245" FontSize="18" />
</Grid>
</Window>

Here is the c# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GasCalculator
{
///
/// Steve Conger
/// Assignment 1
/// 9/30/2010
/// This program calculate miles per gallon
/// and price per mile
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void btnCalculate_Click(object sender, RoutedEventArgs e)
{
//get input
double totalMiles= double.Parse(txtTotalMiles.Text);
double pricePerGallon = double.Parse(txtPricePerGallon.Text);
double totalGallons = double.Parse(txtTotalGallons.Text);

//transform input to output
double milesPerGallon = totalMiles / totalGallons;
double pricePerMile = pricePerGallon / milesPerGallon;

//output the results
lblMilesPerGallon.Content = "The miles per gallon is " + milesPerGallon.ToString();
lblCostPerMile.Content = "The cost per mile is " + pricePerMile.ToString("c");

}


}
}

Wednesday, September 29, 2010

Assignment 1

Here is the xaml code
<Window x:Class="Assignment1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="436" Width="479">
<Grid Background="CornflowerBlue">
<Label Height="28" HorizontalAlignment="Left" Margin="25,40,0,0" Name="label1" VerticalAlignment="Top" Width="132">Enter Beginning Miles</Label>
<TextBox Height="22" Margin="183,40,153,0" Name="txtBeginningMiles" VerticalAlignment="Top" />
<Label Height="28" HorizontalAlignment="Left" Margin="38,88,0,0" Name="label2" VerticalAlignment="Top" Width="120">Enter Ending Miles</Label>
<TextBox Height="23" Margin="185,88,153,0" Name="txtEndingMiles" VerticalAlignment="Top" />
<Label Height="28" HorizontalAlignment="Left" Margin="38,135,0,0" Name="label3" VerticalAlignment="Top" Width="120">Cost Per Gallon</Label>
<TextBox Height="23" Margin="185,135,153,0" Name="txtCostPerGallon" VerticalAlignment="Top" />
<Label HorizontalAlignment="Left" Margin="38,181,0,189" Name="label4" Width="120">Number of Gallons</Label>
<TextBox Margin="185,181,153,194" Name="txtGallons" />
<Button Height="23" HorizontalAlignment="Left" Margin="49,0,0,135" Name="button1" VerticalAlignment="Bottom" Width="75" Click="button1_Click">Calc</Button>
<Label Height="28" HorizontalAlignment="Left" Margin="49,0,0,88" Name="label5" VerticalAlignment="Bottom" Width="120">Miles Per Gallon</Label>
<Label Height="28" Margin="196,0,142,88" Name="lblMilesPerGallon" VerticalAlignment="Bottom">Label</Label>
<Label Height="28" HorizontalAlignment="Left" Margin="49,0,0,50" Name="label6" VerticalAlignment="Bottom" Width="120">Cost per Mile</Label>
<Label Height="28" Margin="0,0,142,50" Name="lblCostPerMile" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="119">Label</Label>
</Grid>
</Window>

Here is the C Sharp code
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Assignment1
{
///
/// Steve Conger
/// 9/29/2010
/// Assignment 1
///

public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
//get the input
double beginningMiles;
beginningMiles = double.Parse(txtBeginningMiles.Text);
double endingMiles = double.Parse(txtEndingMiles.Text);
double costPerGallon = double.Parse(txtCostPerGallon.Text);
double gallonsPurchased = double.Parse(txtGallons.Text);

//converting input to output
double totalMiles = endingMiles - beginningMiles;
double milesPerGallon = totalMiles / gallonsPurchased;
double costPerMile = costPerGallon / milesPerGallon;

//output
lblMilesPerGallon.Content = milesPerGallon.ToString();
lblCostPerMile.Content = costPerMile.ToString("c");
}
}
}

Monday, September 27, 2010

Hello world

using System;
using System.Collections.Generic;
using System.Text;

namespace Hello
{
/*
* this is a hello world program
* it doesn't do much
* steve conger 9/27/2010 */
/// <summary>
///
/// </summary>
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello all you Martians");
Console.ReadKey();
}//end main
}//end class
}//end namespace

Monday, September 6, 2010

Program Preliminaries

For every program I am going to ask you to fill out a worksheet. This is meant to be a way to help you start thinking about the program and what you need to do to write it. It may seem like busy work, but thinking through these questions can save you a lot of time and frustration in the long run. Here is an example of the form filled out for a simple program that tests whether a number is even or odd:


Program Planner


What is the main purpose of your program?
To determine if a number is odd or even
What is the output for your program?
It will return the string "Even" if the number is even, or "Odd" if the number is odd
What is the input needed to get that output?
An integer number
What steps are required to convert the input into the output (algorithm)?
the number input modulus 2
if the remainder is 0 then the output is "Even"
otherwise the output is "Odd"
How will you test that the output is correct?
I will enter an even number to make sure the output is correct, then I will enter an odd number to determine the same.
A non integer number will crash the program
What objects will you use?
Console and Integer


Additionally I will ask you to put a comment header on every program that tells what the assignment is, a brief description of the program, your name and the date. It will look something like this:

/*********************************
* Assignment x
* This program determines if a number
* is even or odd
* Steve Conger
* September 30, 2010
***********************************/