






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







CSE 1301
Figures from Lewis, “C# Software Solutions”, Addison Wesley
CSE 1301 (^) 7-
CSE 1301 (^) 7-
Development^ Use
Maintenance
CSE 1301 (^) 7-
Use and Maintenance
Development
Establish requirements
Create design
Implement code
Test system
Establish requirements
Create design
Implement code
Test system
CSE 1301 (^) 7-
CSE 1301 (^) 7-
CSE 1301 (^) 7-
CSE 1301 (^) 7-
CSE 1301 (^) 7-
CSE 1301 (^) 7-
Rational r1 = new Rational(6, 8); Rational r2 = new Rational(1, 3); Rational r3, r4, r5, r6, r7; Console.Out.WriteLine("First rational number: " + r1); Console.Out.WriteLine("Second rational number: " + r2); if (r1.Equals(r2)) Console.Out.WriteLine("r1 and r2 are equal."); else Console.Out.WriteLine("r1 and r2 are NOT equal."); r3 = r1.Reciprocal(); Console.Out.WriteLine("The reciprocal of r1 is: " + r3); r4 = r1.Add(r2); r5 = r1.Subtract(r2); r6 = r1.Multiply(r2); r7 = r1.Divide(r2); Console.Out.WriteLine("r1 + r2: " + r4); Console.Out.WriteLine("r1 - r2: " + r5); Console.Out.WriteLine("r1 * r2: " + r6); Console.Out.WriteLine("r1 / r2: " + r7); Console.In.ReadLine(); // Wait for enter key
CSE 1301 (^) 7-21 CSE 1301 (^) 7-
Rational
CSE 1301 (^) 7-
CSE 1301 (^) 7-
private void Reduce ( ) { if (numerator != 0) { int common = Gcd(Math.Abs(numerator), denominator);
numerator = numerator / common; denominator = denominator / common; } }
CSE 1301 (^) 7-
CSE 1301 (^) 7-
CSE 1301 (^) 7-
public Account (String name, long acctNumber, double balance) { this.name = name; this.acctNumber = acctNumber; this.balance = balance; }
CSE 1301 (^) 7-
Before
num
5
num
12
After
num
5
num
5
CSE 1301 (^) 7-
Before
bishop1 bishop
After
bishop1 bishop
CSE 1301 (^) 7-
There are three main types of parameters:
using System; namespace ParameterTester { public class Num { private int value; // Sets up the new Num object, storing an initial value. public Num (int update) { value = update; } // Sets the stored value to the newly specified value. public void SetValue (int update) { value = update; }
// Returns the stored integer value as a string. public override string ToString ( ) { return value + ""; } } }
CSE 1301 (^) 7-
using System; namespace ParameterTester { class ParameterPassing { static void Main(string[] args) { ParameterModifier modifier = new ParameterModifier(); int a1 = 111; Num a2 = new Num(222); Num a3 = new Num(333); Console.Out.WriteLine("Before calling changeValues:"); Console.Out.WriteLine("a1\ta2\ta3"); Console.Out.WriteLine(a1 + "\t" + a2 + "\t" + a3 + "\n"); modifier.ChangeValues(a1, a2, a3); Console.Out.WriteLine("After calling changeValues:"); Console.Out.WriteLine("a1\ta2\ta3"); Console.Out.WriteLine(a1 + "\t" + a2 + "\t" + a3 + "\n"); Console.In.ReadLine(); // Wait for enter key } } } (^) CSE 1301 (^) 7-
using System;
namespace ParameterTester { public class ParameterModifier {
public void ChangeValues(int f1, Num f2, Num f3) { Console.Out.WriteLine("Before changing the values:"); Console.Out.WriteLine("f1\tf2\tf3"); Console.Out.WriteLine(f1 + "\t" + f2 + "\t" + f3 + "\n");
f1 = 999; f2.SetValue(888); f3 = new Num(777); Console.Out.WriteLine("After changing the values:"); Console.Out.WriteLine("f1\tf2\tf3"); Console.Out.WriteLine(f1 + "\t" + f2 + "\t" + f3 + "\n"); Console.In.ReadLine(); } } }
CSE 1301 (^) 7-45 CSE 1301 (^) 7-
static void Main() { int a = 42; Console.WriteLine (a); B (a); Console.WriteLine (a); } static void B (int x) { x += 9; Console.WriteLine (x); }
static void Main() { int a = 42; Console.WriteLine (a); B (ref a); Console.WriteLine (a); } static void B (ref int x) { x += 9; Console.WriteLine (x); }