CIS170c week 6 iLab homework

Insert picture here

/* Specification:

Your Name here

Lab 6 Exercise #A

This program does takes password input from the user then asks

the user to confirm the password. It then check to see if the

passwords match. If they do, the user is given an update that

the passwords match. If they do not match, the user is given

an update that the passwords do not match. */

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace LAB6A

{

publicpartialclassForm1 : Form

{

public Form1()

{

InitializeComponent();

this.label2.Visible = false;

this.S.Visible = false;

this.button2.Visible = false;

this.S.Text = "";

}

privatevoid Form1_Load(object sender, EventArgs e)

{

}

// this responds when a user clicks button1

privatevoid button1_Click(object sender, EventArgs e)

{

/* if statement that will instruct the user to renter

password if text has been entered into the first text box */

if (this.initialTextbox.Text != "")

{

this.label2.Visible = true;

this.S.Visible = true;

this.button2.Visible = true;

this.S.Text = "";

this.messageLabel.Text = "To confirm, re-enter your password";

this.messageLabel.Visible = true;

}

else

{

this.label2.Visible = false;

this.S.Visible = false;

this.button2.Visible = false;

this.S.Text = "";

this.messageLabel.Text = "You must enter a password";

this.messageLabel.Visible = true;

}

}

// this responds when a user clicks button2

privatevoid button2_Click(object sender, EventArgs e)

{

/* if statement that will display a final message to

user based on whether the passwords match or not */

if (this.initialTextbox.Text == this.S.Text)

{

MessageBox.Show("Passwords are the same.", "Password Entered");

}

else

{

MessageBox.Show("Passwords are different.", "Password Entered");

}

}

}

}

LAB6B

Insert picture here

/* Specification:

Your Name here

Lab 6 Exercise #B

This program generates a random number, then has the user attempt to guess

the random number between 0 - 100. When the user guesses the number the

program lets you know.*/

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace LAB6B

{

publicpartialclassForm1 : Form

{

// initializing variable

Random r = newRandom();

int generatedRandomNumber;

int numberOfGuesses = 0;

Color initialBackColor;

public Form1()

{

InitializeComponent();

this.guessTextbox.ReadOnly = false;

this.button1.Visible = true;

this.messageLabel.Text = "";

this.messageLabel.Visible = false;

button2.Visible = false;

initialBackColor = this.BackColor;

}

privatevoid Form1_Load(object sender, EventArgs e)

{

generatedRandomNumber = r.Next(0, 100);

this.label2.Text = generatedRandomNumber.ToString();

}

// this responds when a user clicks button1

privatevoid button1_Click(object sender, EventArgs e)

{

// local variables

int guess;

if (this.guessTextbox.Text == "")

return;

guess = int.Parse(guessTextbox.Text);

numberOfGuesses++;

// if statement that compares the user input to the random number generated at the beggining of the program

if (guess < generatedRandomNumber)

{

this.guessTextbox.ReadOnly = true;

this.button1.Visible = false;

this.messageLabel.Text = "Too Low!!";

this.messageLabel.Visible = true;

button2.Visible = true;

this.BackColor = Color.LightSeaGreen;

}

elseif (guess > generatedRandomNumber)

{

this.guessTextbox.ReadOnly = true;

this.button1.Visible = false;

this.messageLabel.Text = "Too High!!";

this.messageLabel.Visible = true;

button2.Visible = true;

this.BackColor = Color.SlateBlue;

}

else

{

MessageBox.Show(String.Format("You are right!! It took you {0} guesses", numberOfGuesses),

"You are a WINNER!!",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

// this responds when a user clicks button2

privatevoid button2_Click(object sender, EventArgs e)

{

this.guessTextbox.ReadOnly = false;

this.button1.Visible = true;

this.messageLabel.Text = "";

this.messageLabel.Visible = false;

button2.Visible = false;

this.BackColor = initialBackColor;

}

}

}