Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Vernon Hills Mail Order Company often sends multiple packages per order. For

ID: 3558706 • Letter: T

Question

The Vernon Hills Mail Order Company often sends multiple packages per order. For each customer order, output a mailing label for each box to be mailed. The mailing labels contain the customer's complete name and address, along with a box number in the form Box 9 of 9. For example, an order that requires three boxes produces three labels: Box 1 of 3, Box 2 of 3, and Box 3 of 3. Design an application that reads records that contain a customer's title (for example, Mrs.), first name, last name, street address, city, state, zip code and number of boxes. The application must read the records until eof is encountered and produce enough mailing labels for each other.

PLEASE USE FLOWCHART.

Thank you!

Explanation / Answer

CreateMailingLabels.cs (source)

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

    public partial class frmCreateOrder : Form

    {

        public frmCreateOrder()

        {

            InitializeComponent();          

        }

        private void btnlblCreate_Click(object sender, EventArgs e)

        {

            //Read from text file 'VernonHillMailOrderBoxes.txt'

            String line;

            String filePath = @"F:\Lorimodule7Chapter.07DataFilesForExercisesVernonHillsMailOrderBoxes.txt";

            //Pass the file path and file name to the StreamReader constructor

            if (File.Exists(filePath))

            {

                StreamReader sr = null;

                //Enclose the file opening, reading, and closing

                //operations in a try catch block to gracefully

                //recover from and handle any exceptions from

                //'File.IO' operations

                try

                {

                    sr = new StreamReader(filePath);                 

                    //Continue to read until you reach end of file

                    while ((line = sr.ReadLine()) != null)

                    {

                        //Get name, address, and number of boxes

                        //Parse the string by separating items

                        //Read the first line from the text file

                        string[] linefromFile = line.Split(',');

                        int boxNum = 0;

                        int boxLength = 0;

                        int count = 0;

                        string name = String.Empty;

                        string address = String.Empty;

                        string addressNum = String.Empty;

                        string numBoxes = String.Empty;

                        //Parse each string in the array then start building

                        //the label by combining array indexes 0, 1, and 2

                        //for the name and title. The array element with index

                        //3 hold the address number, array elements 4, 5, 6 hold

                        //rest of the address. Finally the last element in the

                        //array is the number of boxes index 7.

                        foreach (string s in linefromFile)

                        {

                            boxLength = linefromFile.Length;

                            boxNum = Convert.ToInt32(linefromFile[boxLength - 1].ToString());                       

                            if (count < 3)

                                name += s;

                            if (count > 2 && count < 4)

                                addressNum += s;                          

                            if (count > 3 && count < 7)

                               address += s;                          

                            count++;                         

                        }

                        //Create the label by combining name, address,

                        //and the number of boxes in the form "Box 1 of 5"

                        for (int i = 0; i != boxNum; i++)

                        {

                            int boxCount = i + 1;

                            txtOrder.AppendText( " ");

                            txtOrder.AppendText(name);

                            txtOrder.AppendText(" ");

                            txtOrder.AppendText(addressNum.Trim());

                            txtOrder.AppendText(" ");

                            txtOrder.AppendText(address.Trim());

                            numBoxes = "Box " + boxCount.ToString() + " of " + boxNum.ToString();

                            txtOrder.AppendText(" ");

                            txtOrder.AppendText(numBoxes);

                            txtOrder.AppendText(" ");                          

                        }                      

                    }

                }

                catch (Exception ex)

                {

                    //Log the exception information to the form

                    txtOrder.Text = ("Exception: " + ex.Message);

                }

                finally

                {

                    //Close the file

                    if (sr != null)

                        sr.Close();

                }

            }

        }

        //Close the form by clicking the

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote