Update your “Flowers for Valentine’s Day?” program (Program 2) to include the name of each arrangement type.Your “flowers2.txt” data file will now have data for 15 arrangements.The arrangement name may contain embedded white space and will be by itself on the line before the sales data for that arrangement as shown below.A test data file will be posted in D2L, in the drop boxes for this program and also in Content / Course Materials / Unit 4.Read the names when you read the data and store the names into a 2D array of characters (1D array of C-strings) with each row in parallel with the corresponding row in the sales array.
Red Roses, Arrangement of 3
856.43 386.54785.341043.601534.872544.66
Springtime Bouquet
1247.50 290.54506.80899.651440.653006.99
…
Add a menu with 2 options as shown below:
1.Print All with Totals
2.Search for Sales Data
3.Exit
Print All with Totals:Print all data with row totals to the right of each row, column totals below each column, and the overall total in the lower right corner of the table.Label each row with the arrangement name.Label each column with the day name (Monday through Saturday).
Search for Sales Data:Allow the user to enter a full or partial arrangement name.Print the data for the arrangements that contain all or part of the name entered, using the same format described above for Print All.
This version of your program must use only c-strings (include cstring) and must not use the string class (do not include string)
Part 2, The String Class
Update your “Flowers for Valentine’s Day?” program (Program 2) as described above, but use only string objects (include string) instead of c-style strings (do not include cstring).
Both Programs
Both programs must be modular.Use separate functions to read the data file, print the menu, and perform each menu selection.Your output should be well-organized, neat, and easy to read.
Design each of your programs by completing the CS 250 Program Design Document.You may use a separate document for each program or put both designs into the same document.Include a structure chart, prototype and brief description for each function and time estimates for program design, coding each function, program testing, and total time.If you put both designs in the same file, you may use one structure chart, if you like.
Save the designs in files named FlowersDesignCstring_xxx.doc and FlowersDesignString_xxx.doc or just FlowersDesign_xxx.doc if using one file, where xxx are your initials.Submit your design file(s) in the Program #4 Design drop box by the due date shown in the calendar.
Write both programs.I recommend writing the c-string version first as it generally takes more time.Save it, make a copy and update the copy to be the string version.
Save your c-string program in a file named flowers_cstring_xxx.cpp where xxx are your initials.
Save your string program in a file named flowers_string_class_xxx.cpp where xxx are your initials.
Compile, run, test, and debug both programs.
Update your Program Design Documents.Update the structure chart & function descriptions to fit your working program.Record the actual time spent.
Submit your updated design documents and working .cpp files in the Program #4 drop box by the due date shown in the calendar.You should submit a total of 2 .cpp file in this drop box and 1 or 2 .doc files.
Here is my un-updated program
#include
#include
#include
#include
using namespace std;
const int ROWS = 4;
const int COLS = 6;
// function to calculate the row totals
// need to get the row, the move through the columns for that row to
// get the total for that row
// move to the next row and repeat process
// store the row totals into a 1D array
float readData(float sales[][COLS], int ROWS);
void CalcRowTotals(const float ary2d[][COLS], float row_totals[],int rows);
void calcColTotals(const float ary2d[][COLS],int rows, float col_totals[]);
float calc2dAryTotal(const float ary2d[][COLS], int rows);
void print2dAry(float sales[][COLS],float row_totals[], int rows,float col_totals[], float total);
int main()
{
float total;
// rows are items, Colsare days M -F
float sales[ROWS][COLS];
float item_totals[ROWS] = {0};
float day_total[COLS] = {0};
sales[ROWS][COLS] = readData(sales, ROWS);
//cout
total = calc2dAryTotal (sales, ROWS);
CalcRowTotals(sales,item_totals, ROWS);
calcColTotals(sales, ROWS , day_total);
print2dAry (sales ,item_totals, ROWS, day_total, total);
cout
return 0;
}
float readData(float sales[][COLS], int ROWS)
{
ifstream infile;
infile.open("flowers.txt");
if (!infile) {
cout
exit(1);// call system to stop
}
/* end code read text file */
for (int i = 0; i
{
for (int j = 0; j
{
if (!(infile >> sales[i][j]))
{
cout
exit(1);// call system to stop
}
}
}
infile.close();
return sales[ROWS][COLS];
}
float calc2dAryTotal(const float ary2d[][COLS], int rows)
{
float total = 0;
//move through each row... processing all colums in one row
// before moving to the next row
for(int r= 0; r
{
//process a row
for (int c=0; c
{
total += ary2d[r][c];
}
}
return total;
}
// calculate the row totals of a 2D array
// pass in the 2D array and the number of rows in it
// pass out the row totals
void CalcRowTotals(const float ary2d[][COLS], float row_totals[],int rows)
{
for(int r=0; r
{
row_totals[r] = 0;
for(int c = 0; c
{
row_totals[r] += ary2d[r][c];
}
}
}
void calcColTotals(const float ary2d[][COLS],int rows, float col_totals[])
{
for(int c = 0; c
{
col_totals[c] = 0;
for(int r = 0; r
{
col_totals[c] += ary2d[r][c];
}
}
}
void print2dAry(float sales[][COLS],float row_totals[], int rows,float col_totals[], float total)
{
cout
cout
//move through each row... processing all colums in one row
// before moving to the next row
for(int r= 0; r
{
cout
//process a row
for (int c=0; c
{
cout
}
cout
}
//print col totals
cout
for(int c=0; c
{
cout
}
cout
cout
}