Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help please! Assiqnment Instructions: Read each step's instructions carefully before you write any code. In this assignment, you'll create the basic parts of a spreadsheet

Help please!image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Assiqnment Instructions: Read each step's instructions carefully before you write any code. In this assignment, you'll create the basic parts of a spreadsheet application. Most of the formula and computation-oriented functionality will be implemented in later assignments so you won't be implementing the entire application in one week. But this assignment lays the foundation and it important because you will build on top of it in future assignments. Using Visual Studio, create a WinForms application and name it "Spreadsheet_FirstName_LastName" (without quotes). So for example if your name is Alex Smith then the project name would be Spreadsheet_Alex_Smith. Put your name should also appear in the header comments of every code file. After creating the application, drag a DataGridView (another link here with info about properties, methods and events) control into the window. This control gives you a spreadsheet-like array of cells, but requires some setup. It initially looks like this (image below) when you first add it to the form: In the properties tool window there is a Columns property for the grid view. Click the".." button next to it to open up the column editor. Here you can add columns. Experiment with adding a few columns, say A, B, C, and D Edit Columns Selected Columns Unbound Column Properties ColumnType False HeaderText MadnputLength 3276 False Automatic ToolTipText Indicates the name used in code to identify the object Remove Cancel Note that the HeaderText property is what actually appears as the column header in the control. You can also add rows in the designer but we want to do this programmatically to save time Step 1- Create Columns A to Z with code Set the AllowUserToAddRows and AllowUserToDeleteRows properties to false. We will create a fixed number of rows and columns for our spreadsheet. In the form's constructor, or in the OnLoad event, write code to programmatically create columns A to Z. If you've added some columns in the designer you'll want to clear those first (see the Clear method). There is also an Add method so investigate this. Right click the solution (not the project) in the "Solution Explorer" tool window and go to "Add" then click "New Project...". Select "Class Library" as the type Choose a reasonable name for it. I have chosen "SpreadsheetEngine" for mine. Click the "OK" button to create it. In the WinForms app add the class library to the references. In the window that pops up when you add a new DLL reference, there's an option to reference one that's within the solution. Choose that 1. 2. 3. 4. You will have a solution in Visual Studio that has two projects in it at this point. One is a Winforms application and the other is a class library. Remember the idea behind having the logic in a class library is that you're decoupling it from the WinForms code. So do not reference System.Windows.Forms in that DLL project Step 4-Create and implement the "Cell" class In the class library code, create and implement the "Cell" or "SpreadsheetCell", (or some other similar name of your choosing) class. This class represents one cell in the worksheet. Implement it in the CptS321 namespace (namespace CptS321 class Cellmplement this class to obey the rules listed belovw It must be an abstract base class t (the class itself) must be declared publicly so the world outside of the class library can see it Add a Rowlndex property that is read only (set in constructor and returned through the get) . Add a Columnlndex property that is read only (set in constructor and returned through the get) . It must have a string "Text" property that represents the actual text that's typed into the cell Recall that a property is essentially a getter/setter. So make this property a getter and setter for a member variable that's marked as protected o The getter can just return the protected property o The setter must do the following If the text is being set to the exact same text then just ignore it. Do not invoke the property change event (discussed below) if the property isn't actually being changed If the text is actually being changed then update the private member variable and fire the PropertyChanged event, which is discussed in the next bullet point. 1. 2. Make the spreadsheet cell class implement the INotifvPropertyChanged interface (declared in the System.ComponentModel namespace o We need a way for the logic engine in this class library to notify other the Ul layer whern o Implementing this interface allows the cell to notify anything that subscribes to this o Going back to the point mentioned above, call the PropertyChanged event (just like o We discussed this in class but if you don't know how this works you'll have to read up on changes have been made to the spreadsheet event that the "Text" property has changed calling a function) when the text changes events and the INotifyPropertyChanged interface. This page is a good start. It talks about properly implementing this interface t must have a Value property that's also a string. Like the Text property this needs to be a protected member variable that is exposed through a property. o This represents the "evaluated" value of the cell. It will just be the Text property if the text doesn't start with the '' character. Otherwise it will represent the evaluation of the formula that's type in the cell. 4 o Since many formulas in spreadsheet cells reference other cells we need for the actual spreadsheet class to set this value. o However, we don't want the "outside world" (outside of the spreadsheet class) to set this value so you must design it so that only the spreadsheet class can set it, but anything can get it. The big hint for this: It's a protected property which means inheriting classes can see it. Inheriting classes should NOT be publically exposed to code outside the class library. o o So to summarize, this Value property is a getter only and you'll have to implement a way to allow the spreadsheet class to set the value, but no other class can. In the class library code implement the Spreadsheet" (or some similar name of your choosing) class The spreadsheet object will serve as a container for a 2D array of cells. It will also serve as a factory for cells, meaning it is the entity that actually creates all the cells in the spreadsheet. Remember that the cell class is abstract, so the outside world can't create an instance of a cell It can only get a reference to a cell from the spreadsheet object. Have a constructor for the spreadsheet class that takes a number of rows and columns. For the WinForm in this assignment we made a fixed number of rows and columns, but we don't want the spreadsheet object to have the "dimensions" to be hard coded. So the constructor should allocate a 2D array (or 1D if you want to do the indexing math for all the cell retrieval functions) of cells * Initialize the array of cells and make sure to give them proper Rowlndex and Columnlndex values o Again, you need to come up with a design here that actually allows the spreadsheet to create cells and there were hints before about how to do this. You cannot make the publically declared cell class non-abstract Make a CellPropertyChanged event in the spreadsheet class. This will serve as a way for the outside world (like the Ul) to subscribe to a single event that lets them know when any property for any cell in the worksheet has changed. The spreadsheet class has to subscribe to all the PropertyChanged events for every cell in order to allow this to happen This is where the spreadsheet will set the value for a particular cell if its text has just changed. The implementation of this is discussed more in step 6 When a cell triggers the event the spreadsheet will "route" it by calling its CellPropertyChanged event o o o Make a GetCell function that takes a row and column index and returns the cell at that location or null if there is no such cell. The return type for this method should be the abstract cell class declared in step 4 Add properties ColumnCount and RowCount that return the number of columns and rows in the spreadsheet, respectively . The rules are if the text of the cell has just changed then the spreadsheet is responsible for updating the Value of the cell. If the Text of the cell does NOT start with'-then the value is just set to the text. Otherwise the value must be computed based on the formula that comes after the . o Future versions (later homework assignments) will go much further with this but now we'll only support one type of formula Support pulling the value from another cell. So if you see the text in the cell starting with o then assume the remaining part is the name of the cell we need to copy a value from. It's not required for this assignment, but in the future we'll need a way to deal with circular references (cell A gets value from B but B gets value from A), so keep that in mind o directly setting the values in the DataGridView cells as opposed to setting them in the Spreadsheet object's cells Spreadsheet Cpts 321 This is cell B1 This is cell B2 3 This is cell B3 1 I love C#! 2 I love C#! I love C#! I love C#! 4 This is cell B I love C#! I love C#! 5 This is cell B5 6 This is cell B6 7 This is cell B7 8 This is cell B8 9 This is cell B9 0 This is cell B10 11 This is cell B11 2 This is cell B12 13 This is cell B13 4 This is cell B14 15 This is cell B15 16 This is cell B16 17 This is cell 817 18 This is cell B18 0 Thie ie cell R19 I love C#! I love C#! |ilove C#! I love C#! I love C#! I love C#! I love C#! I love C#! Point breakdown (the assignment is worth 10 points 6 points for implementing the correct functionality as stated above Assiqnment Instructions: Read each step's instructions carefully before you write any code. In this assignment, you'll create the basic parts of a spreadsheet application. Most of the formula and computation-oriented functionality will be implemented in later assignments so you won't be implementing the entire application in one week. But this assignment lays the foundation and it important because you will build on top of it in future assignments. Using Visual Studio, create a WinForms application and name it "Spreadsheet_FirstName_LastName" (without quotes). So for example if your name is Alex Smith then the project name would be Spreadsheet_Alex_Smith. Put your name should also appear in the header comments of every code file. After creating the application, drag a DataGridView (another link here with info about properties, methods and events) control into the window. This control gives you a spreadsheet-like array of cells, but requires some setup. It initially looks like this (image below) when you first add it to the form: In the properties tool window there is a Columns property for the grid view. Click the".." button next to it to open up the column editor. Here you can add columns. Experiment with adding a few columns, say A, B, C, and D Edit Columns Selected Columns Unbound Column Properties ColumnType False HeaderText MadnputLength 3276 False Automatic ToolTipText Indicates the name used in code to identify the object Remove Cancel Note that the HeaderText property is what actually appears as the column header in the control. You can also add rows in the designer but we want to do this programmatically to save time Step 1- Create Columns A to Z with code Set the AllowUserToAddRows and AllowUserToDeleteRows properties to false. We will create a fixed number of rows and columns for our spreadsheet. In the form's constructor, or in the OnLoad event, write code to programmatically create columns A to Z. If you've added some columns in the designer you'll want to clear those first (see the Clear method). There is also an Add method so investigate this. Right click the solution (not the project) in the "Solution Explorer" tool window and go to "Add" then click "New Project...". Select "Class Library" as the type Choose a reasonable name for it. I have chosen "SpreadsheetEngine" for mine. Click the "OK" button to create it. In the WinForms app add the class library to the references. In the window that pops up when you add a new DLL reference, there's an option to reference one that's within the solution. Choose that 1. 2. 3. 4. You will have a solution in Visual Studio that has two projects in it at this point. One is a Winforms application and the other is a class library. Remember the idea behind having the logic in a class library is that you're decoupling it from the WinForms code. So do not reference System.Windows.Forms in that DLL project Step 4-Create and implement the "Cell" class In the class library code, create and implement the "Cell" or "SpreadsheetCell", (or some other similar name of your choosing) class. This class represents one cell in the worksheet. Implement it in the CptS321 namespace (namespace CptS321 class Cellmplement this class to obey the rules listed belovw It must be an abstract base class t (the class itself) must be declared publicly so the world outside of the class library can see it Add a Rowlndex property that is read only (set in constructor and returned through the get) . Add a Columnlndex property that is read only (set in constructor and returned through the get) . It must have a string "Text" property that represents the actual text that's typed into the cell Recall that a property is essentially a getter/setter. So make this property a getter and setter for a member variable that's marked as protected o The getter can just return the protected property o The setter must do the following If the text is being set to the exact same text then just ignore it. Do not invoke the property change event (discussed below) if the property isn't actually being changed If the text is actually being changed then update the private member variable and fire the PropertyChanged event, which is discussed in the next bullet point. 1. 2. Make the spreadsheet cell class implement the INotifvPropertyChanged interface (declared in the System.ComponentModel namespace o We need a way for the logic engine in this class library to notify other the Ul layer whern o Implementing this interface allows the cell to notify anything that subscribes to this o Going back to the point mentioned above, call the PropertyChanged event (just like o We discussed this in class but if you don't know how this works you'll have to read up on changes have been made to the spreadsheet event that the "Text" property has changed calling a function) when the text changes events and the INotifyPropertyChanged interface. This page is a good start. It talks about properly implementing this interface t must have a Value property that's also a string. Like the Text property this needs to be a protected member variable that is exposed through a property. o This represents the "evaluated" value of the cell. It will just be the Text property if the text doesn't start with the '' character. Otherwise it will represent the evaluation of the formula that's type in the cell. 4 o Since many formulas in spreadsheet cells reference other cells we need for the actual spreadsheet class to set this value. o However, we don't want the "outside world" (outside of the spreadsheet class) to set this value so you must design it so that only the spreadsheet class can set it, but anything can get it. The big hint for this: It's a protected property which means inheriting classes can see it. Inheriting classes should NOT be publically exposed to code outside the class library. o o So to summarize, this Value property is a getter only and you'll have to implement a way to allow the spreadsheet class to set the value, but no other class can. In the class library code implement the Spreadsheet" (or some similar name of your choosing) class The spreadsheet object will serve as a container for a 2D array of cells. It will also serve as a factory for cells, meaning it is the entity that actually creates all the cells in the spreadsheet. Remember that the cell class is abstract, so the outside world can't create an instance of a cell It can only get a reference to a cell from the spreadsheet object. Have a constructor for the spreadsheet class that takes a number of rows and columns. For the WinForm in this assignment we made a fixed number of rows and columns, but we don't want the spreadsheet object to have the "dimensions" to be hard coded. So the constructor should allocate a 2D array (or 1D if you want to do the indexing math for all the cell retrieval functions) of cells * Initialize the array of cells and make sure to give them proper Rowlndex and Columnlndex values o Again, you need to come up with a design here that actually allows the spreadsheet to create cells and there were hints before about how to do this. You cannot make the publically declared cell class non-abstract Make a CellPropertyChanged event in the spreadsheet class. This will serve as a way for the outside world (like the Ul) to subscribe to a single event that lets them know when any property for any cell in the worksheet has changed. The spreadsheet class has to subscribe to all the PropertyChanged events for every cell in order to allow this to happen This is where the spreadsheet will set the value for a particular cell if its text has just changed. The implementation of this is discussed more in step 6 When a cell triggers the event the spreadsheet will "route" it by calling its CellPropertyChanged event o o o Make a GetCell function that takes a row and column index and returns the cell at that location or null if there is no such cell. The return type for this method should be the abstract cell class declared in step 4 Add properties ColumnCount and RowCount that return the number of columns and rows in the spreadsheet, respectively . The rules are if the text of the cell has just changed then the spreadsheet is responsible for updating the Value of the cell. If the Text of the cell does NOT start with'-then the value is just set to the text. Otherwise the value must be computed based on the formula that comes after the . o Future versions (later homework assignments) will go much further with this but now we'll only support one type of formula Support pulling the value from another cell. So if you see the text in the cell starting with o then assume the remaining part is the name of the cell we need to copy a value from. It's not required for this assignment, but in the future we'll need a way to deal with circular references (cell A gets value from B but B gets value from A), so keep that in mind o directly setting the values in the DataGridView cells as opposed to setting them in the Spreadsheet object's cells Spreadsheet Cpts 321 This is cell B1 This is cell B2 3 This is cell B3 1 I love C#! 2 I love C#! I love C#! I love C#! 4 This is cell B I love C#! I love C#! 5 This is cell B5 6 This is cell B6 7 This is cell B7 8 This is cell B8 9 This is cell B9 0 This is cell B10 11 This is cell B11 2 This is cell B12 13 This is cell B13 4 This is cell B14 15 This is cell B15 16 This is cell B16 17 This is cell 817 18 This is cell B18 0 Thie ie cell R19 I love C#! I love C#! |ilove C#! I love C#! I love C#! I love C#! I love C#! I love C#! Point breakdown (the assignment is worth 10 points 6 points for implementing the correct functionality as stated above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify three improper customer etiquette behaviors.

Answered: 1 week ago