Hi
I would like know if the sloution of this task right or not?
If its wrong please comments it.
I will be very thankful.

In this task, you should show that you can solve problems using Top Down Design and construct programs in which their own defined methods exist.
Use Top Down Design to develop a program to assess the readability of a text string consisting of one or more sentences. The program's users to enter a text string with a readability analysis of the program.
The analysis will be to calculate how many words in the average sentences composed. For example, the following text string,
"An example. A sentence ends with a period. Paragraph and end."
consists of three sentences and ten words. Average number of words per sentence is 10/3 = 3.333333.
The more words, on average sentences consist of, the more difficult to read the text usually considered.
Assume that before each word is always a kind of character, '', except for the text string first word. Assume that all sentences end with the dot character, '.'. You do not take into account any other whitespace, punctuation, abbreviations and other things that can complicate the analysis.
Describe your steps in the Top Down Design in your documents, at least two steps to be reported. The reported solution should be consistent with the application you have built. Present also project folder for the developed program.

using System;
using System.Windows.Forms;
using System.Drawing;

namespace Task_1
{
    public class MainForm:Form {

    Panel panCalc;
    Label lblText, lblResult;
    TextBox txtText;
    Button bEqu,bClr;

    public MainForm() {
        try {
            // initiating controls:

            this.Text = "Text Calculator";
            panCalc = new Panel();

            lblText = new Label();
            txtText = new TextBox();
            lblText.Location = new Point(10,10);
            lblText.Size = new Size(250,15);
            lblText.Text = "Please input the text:";
            lblText.BackColor = Color.Orange;
            lblText.RightToLeft = RightToLeft.Yes;
            txtText.Location = new Point(10,30);
            txtText.Size = new Size(250,15);
            txtText.ReadOnly = false;
            txtText.Multiline = true;
            txtText.RightToLeft = RightToLeft.Yes;

            bEqu = new Button();
            bEqu.Size = new Size(150,25);
            bEqu.Location = new Point(10,50);
            bEqu.Text = "Calculate";
            bEqu.BackColor = Color.Orange;
            bEqu.Click += new EventHandler(btn_equ);

            bClr = new Button();
            bClr.Size = new Size(70,25);
            bClr.Location = new Point(170,50);
            bClr.Text = "Clear";
            bClr.BackColor = Color.White;
            bClr.Click += new EventHandler(btn_clr);

            lblResult = new Label();
            lblResult.Location = new Point(10,80);
            lblResult.Size = new Size(250,15);
            lblResult.Text = "";
            lblResult.BackColor = Color.Orange;
            lblResult.RightToLeft = RightToLeft.Yes;

            panCalc.Size = new Size(250,100);
            panCalc.Controls.Add(lblText);
            panCalc.Controls.Add(txtText);
            panCalc.Controls.Add(bEqu);
            panCalc.Controls.Add(bClr);
            panCalc.Controls.Add(lblResult);

            this.Size = new Size(250,125);
            this.Controls.Add(panCalc);

        } catch (Exception e) {
            Console.WriteLine("error ......  " + e.StackTrace);
        }
    }

    private static void Main() {
        Application.Run(new MainForm());
    }

    private void btn_clr(object obj, EventArgs ea) {
        // clearing the controls:

        txtText.Text = "";
        lblResult.Text = "";
        txtText.Focus();
    }

    private void btn_equ(object obj, EventArgs ea) {
        // splitting the text:

        var splitToSentences = txtText.Text.Split(new[] {'.', '!', '?'}, StringSplitOptions.RemoveEmptyEntries);
        var splitToWords = txtText.Text.Split(new[] {'.', ' ', '!', '?'}, StringSplitOptions.RemoveEmptyEntries);

        // the result is calculated as [number of words / number of sentences]

        lblResult.Text = string.Format( "{0:0.00000}", (splitToWords.Length / splitToSentences.Length) );
    }

    }
}

Recommended Answers

All 4 Replies

What you've coded works, but from what I understand of Top Down Design, I think you might want to consider it a little differently.

loop through the complete text by character to build a collection of sentences
then loop through each sentence by character to build a collection of words
then using the size of each collection calculate the average number of word per sentence

I think this will more closely conform to Top Down Design, take a problem and break it down into steps to make it more manageable.

Thanks Sir!
As I'm uderstand you right, I do not use the top-down desigen to solve this task?
Please give more conncret answer Yes Or Not? so that I can change it !

In my opinion no.

Thanks Sir for your answer, Top Down Design is not use in this task.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.