Exercise 6 Introduction to C# CIS-2320. 2 Create a class called ParseDates that will parse a formatted string containing a date into separate integers.

Slides:



Advertisements
Similar presentations
Enumerated data type & typedef. Enumerated Data Type An enumeration consists of a set of named integer constants. An enumeration type declaration gives.
Advertisements

ENUMERATED, typedef. ENUMERATED DATA TYPES An enumeration consists of a set of named integer constants. An enumeration type declaration gives the name.
Line Efficiency     Percentage Month Today’s Date
Unit Number Oct 2011 Nov 2011 Dec 2011 Jan 2012 Feb 2012 Mar 2012 Apr 2012 May 2012 Jun 2012 Jul 2012 Aug 2012 Sep (3/4 Unit) 7 8 Units.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
Composite types Cartesian products –tuples, records, structures disjoint unions –union, discriminated or variant records mappings –arrays, functions recursive.
PHP and XML. Visual Studio/File/New/File I have switched to Visual Studio to make the XML – I think it provides an easier interface for creating an XML.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Working with Unmanaged Code.
Select (drop-down list) Inputs. Insert/Form/List Menu.
Exercise 2 Introduction to C# CIS Create a class called Employee that contains the following private instance variables: Social Securitystring.
ProjectImpactResourcesDeadlineResourcesDeadline Forecast Plan Time Resources Risk 001xx 002xx 003xx 004xx 005xx 006xx 007xx TotalXX Example 1: Portfolio.
14 BirthMonth1February BirthMonth CE : Fundamental Programming Techniques.
Windows Server 2008 R2 Oct 2009 Windows Server 2003
Basic View Main Menus Sub Menus 9-Aug-01 8-Aug-01 7-Aug-01 6-Aug-01
Jan 2016 Solar Lunar Data.
IT Strategy Roadmap Template

Q1 Jan Feb Mar ENTER TEXT HERE Notes
Jul Aug Sept Oct Nov Dec Jan Feb Mar Apr May Jun

Project timeline # 3 Step # 3 is about x, y and z # 2
Average Monthly Temperature and Rainfall
80-Hour SHARP Certification Course Schedule


Mammoth Caves National Park, Kentucky
2017 Jan Sun Mon Tue Wed Thu Fri Sat
Timeline PowerPoint Template

Gantt Chart Enter Year Here Activities Jan Feb Mar Apr May Jun Jul Aug
Jul Aug Sept Oct Nov Dec Jan Feb Mar Apr May Jun
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Free PPT Diagrams : ALLPPT.com


Wireless Local Number Portability Timeline - Phase 2
Step 3 Step 2 Step 1 Put your text here Put your text here
Calendar Year 2009 Insure Oklahoma Total & Projected Enrollment
MONTH CYCLE BEGINS CYCLE ENDS DUE TO FINANCE JUL /2/2015
Jan Sun Mon Tue Wed Thu Fri Sat
Analysis & Disclosure of customer complaints

©G Dear 2008 – Not to be sold/Free to use
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ITEM 1 ITEM 2 ITEM 3
Electricity Cost and Use – FY 2016 and FY 2017
QUIZ.

01 DRAW YOUR TIMELINE HERE JAN. MAR. JAN. MAR. FEB. APR. FEB. APR.
Independent Variables
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Free PPT Diagrams : ALLPPT.com


Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Objective - To make a line graph.
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Project timeline # 3 Step # 3 is about x, y and z # 2
TIMELINE NAME OF PROJECT Today 2016 Jan Feb Mar Apr May Jun
Wireless Local Number Portability Timeline - Phase 2

Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Pilot of revised survey
Presentation transcript:

Exercise 6 Introduction to C# CIS-2320

2 Create a class called ParseDates that will parse a formatted string containing a date into separate integers (these are to be private members) containing the month, day, and year. The constructor is to be passed a char variable indicating how the string is formatted and a string variable containing the date to be parsed. It will then break this string down into a month, day and year. Here are the various options: OptionString formatExample Result Month Day Year 'R'mm/dd/yyyy10/15/ 'Y'yyyy/mm/dd2006/01/ 'A'dd-mmm-yyyy15-NOV 'F'Mmmmm dd,yyyy Or Mmmmm dd, yyyy June 5,2006 Or June 5, 'P'mm.dd.yyyy

3 Add these read-only properties to the class: Month- returns the integer member month Day- returns the integer member day Year- returns the integer member yesr

4 Next, create a Windows application to test this class. Design a form similar to the following:

5 The user will select the format for the date to be entered using a ComboBox and then enter a date in that format.

6 When the user presses the tab key, create an instance of the ParseDates class passing the selected option and the date entered to the constructor. When control returns to the application use the ParseDates’s properties to populate the Month, Day, and Year boxes. Then give focus to the Another button. When this button is clicked reset the form to its initial display.

7 private void txtDateEntered_Leave(object sender, System.EventArgs e) { char theOne = ' '; switch ( cmbDateFormat.SelectedIndex ) { case 0 : theOne = 'R'; break; case 1 : theOne = 'Y'; break; case 2 : theOne = 'P'; break; case 3 : theOne = 'A'; break; case 4 : theOne = 'F'; break; } ParseDates PD = new ParseDates( theOne, txtDateEntered.Text ); txtMonth.Text = PD.Month.ToString(); txtDay.Text = PD.Day.ToString(); txtYear.Text = PD.Year.ToString(); } private void btnQuit_Click(object sender, System.EventArgs e) { Dispose(); } private void bthAnother_Click(object sender, System.EventArgs e) { txtMonth.Text = ""; txtDay.Text = ""; txtYear.Text = ""; txtDateEntered.Text = ""; cmbDateFormat.SelectedIndex = 0; cmbDateFormat.Focus(); }

8 namespace CSExerciseParse { public class ParseDates { private int month; private int day; private int year; private string work; private int i; private string [] mthAbbrev = new string[12] { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; public ParseDates( char format, string strDate ) { work = strDate; string temp = ""; switch (format) { case 'R' : i = work.IndexOf('/'); month = int.Parse( work.Substring(0, i) ); work = work.Remove(0, i+1); i = work.IndexOf('/'); day = int.Parse( work.Substring(0, i) ); work = work.Remove(0, i+1); year = int.Parse( work.Substring(0, work.Length ) ); break; // <========= more code here

9 case 'A' : i = work.IndexOf('-'); day = int.Parse( work.Substring(0, i) ); work = work.Remove(0, i+1); i = work.IndexOf('-'); temp = work.Substring(0, i); work = work.Remove(0, i+1); for ( i = 0; i < 12; i++) { if ( temp == mthAbbrev[i] ) break; } month = i + 1; year = int.Parse( work.Substring(0, work.Length ) ); break; default : month = 0; day = 0; year = 0; break; } // end of switch } // end of constructor // <========== properties go here } // end of ParseDates class } // end of namespace