help neede regarding swith statement

hi! can any body plzz help in solving this ques i am sending the question and answer which i write...it's working correctly but still i think there is some problem in it... i don't know hpw to use the switch statement if any body can help then....plzzzz

**********************************************************************
Here is the ques...

write a program that makes use of standard input and output, conditional braching, variables, simple mathematical and relational operators, loops, arrays, basic putput formatting and a variety of data types.

specification

the user will be presented with a program menu contaning the following layout?:


SWELL SIZE ANALYSIS PROGRAM
===========================

1) Enter swell size figures
2) Analyse swell size figures
3) Exit program

Enter option:

use a swith statement to evaluate and execute the option chosen.

if the user chooses option 1, they will be required to enter 7 Swell Size figures (in mtrs). use the following layout:



SWELL SIZE FOR WEEK
--------------------------------------

Enter Day 1 mtrs: .5
Enter Day 2 mtrs: 1
Enter Day 3 mtrs: 1.5
Enter Day 4 mtrs: 0
Enter Day 5 mtrs: 4
Enter Day 6 mtrs: 2
Enter Day 7 mtrs: 2.5

Press any to continue

write a function to load the 7 days Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant in the array.
loadarray(swell_size,MAXDAYS);


if the user chooses option 2, the program will analyse the Swell Size data and display the results using the following layout:





SWELL SIZE FOR WEEK
--------------------------------------

Day mtrs
1 0.5
2 1.0
3 1.5
4 0.0
5 4.0
6 2.0
7 2.5

total mtrs : 11.5
average mtrs : 1.6
minimum mtrs : 0.0
maximum mtrs : 4.0

Press any to continue


assume that the user always runs option 1 beforerunning option 2. you do not need to write error checking for this.

write a function to display the 7 Swell Size figures. it should accept 2 parameters, the array name and the number of itens in the array. it should display the 7 Swell Size figures as shown above. in the following example, swell_size is the array name and MAXDAYS is a constant set to the number of items in the array.

disparray(swell_size,MAXDAYS);

write a function to Total 7 Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant set to th numbers of items in the array.
sumarray(swell_size,MAXDAYS);

write a function to determine the Minimum Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant set to th numbers of items in the array.
minarray(swell_size,MAXDAYS);

write a function to determine the Maximum Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant set to th numbers of items in the array.
maxarray(swell_size,MAXDAYS);

if the user chooses option 3, the program will exit.

for options 1 and 2, the program is to return t the menu after completing the respective tasks.

you are design the program using structure diagrams.

create a test plan for your application based on the specification.

**********************************************************************

here is ans..which i write

/*
-----------------------------------------------
Auther : Prati
Created:
Purpose:
Amended:
----------------------------------------------
*/

//--- include header files -------------------

#include // stream I/O (cout, endll etc.)
#include // operating system console I/O routines
#include // stream I/O manipulators

//--- main program-----------------------------------
void main()
{ // main program starts

// declare constants
const int MAXDAYS = 7;

// declare variables
int count; // loop control variable
float total; //
float average; //
float minimum; // minimum sale
float maximum; // maximum sale

// declare monthly sales array
float swell_size[MAXDAYS];

// declare title
clrscr();
cout << "SWELL SIZE ANALYSIS PROGRAM" << endl;
cout << "===========================" << endl;
cout << endl;

// prompt for and get each month sales
for(count=0;count<MAXDAYS;count++)
{
cout << "Enter Day " << (count+1) << " mtrs: ";
cin >> swell_size[count];
}
cout << endl;

// display report headings
clrscr(); // clear screen
cout << "SWELL SIZE FOR WEEK" << endl;
cout << "-------------------" << endl;
cout << setiosflags(ios::right)
<< setw(5) << "Enter Day 1 mtrs"
<< setw(10) << ":"
<< endl;

// display sales for each month
count=0; // initialise loop counter
while(count<MAXDAYS) // while loop starts
{
cout << setiosflags(ios::right)
<< setw(5) << (count+1)
<< setprecision(2)
<< setiosflags(ios::fixed)
<< setw(10) << swell_size[count]
<< endl;
count = count+1; // increment loop counter
}

// calculate Total, Average, Minimum and maximum

count=0; // initialise loop counter
total=0.0; // initialise total
average=0.0; // initialise average
minimum=swell_size[0]; // initialise minimum to first array element
maximum=swell_size[0]; // initialese maximum to first array element

// loop through total
do
{
// accumulate total
total = total+swell_size[count];

// check for new minimum
if (swell_size[count]<minimum)
{
minimum = swell_size[count]; // new minimum
}

// check for new maximum
if (swell_size[count]>maximum)
{
maximum = swell_size[count]; // new maximum
}
count = count+1; // increment loop counter
}
while (count<MAXDAYS); // loop ends

// calculate average
average = total/count;

// display sales Analysis
cout << endl << endl;

cout << "Total $ " << total << endl;
cout << "Average $ " << average << endl;
cout << "Minimum $ " << minimum << endl;
cout << "Maximum $ " << maximum << endl << endl;

// display end of program
cout << "End of Program" << endl << endl;
cout << "Press any key to continue...";
getch();

} // main program ends

******************************************************************

hope to receive any ans soon...
thanks
bye

Comments

  • Check out this site:
    http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=112&MsgID=261328&Setting=A9999F0001

    : hi! can any body plzz help in solving this ques i am sending the question and answer which i write...it's working correctly but still i think there is some problem in it... i don't know hpw to use the switch statement if any body can help then....plzzzz
    :
    : **********************************************************************
    : Here is the ques...
    :
    : write a program that makes use of standard input and output, conditional braching, variables, simple mathematical and relational operators, loops, arrays, basic putput formatting and a variety of data types.
    :
    : specification
    :
    : the user will be presented with a program menu contaning the following layout?:
    :
    :
    : SWELL SIZE ANALYSIS PROGRAM
    : ===========================
    :
    : 1) Enter swell size figures
    : 2) Analyse swell size figures
    : 3) Exit program
    :
    : Enter option:
    :
    : use a swith statement to evaluate and execute the option chosen.
    :
    : if the user chooses option 1, they will be required to enter 7 Swell Size figures (in mtrs). use the following layout:
    :
    :
    :
    : SWELL SIZE FOR WEEK
    : --------------------------------------
    :
    : Enter Day 1 mtrs: .5
    : Enter Day 2 mtrs: 1
    : Enter Day 3 mtrs: 1.5
    : Enter Day 4 mtrs: 0
    : Enter Day 5 mtrs: 4
    : Enter Day 6 mtrs: 2
    : Enter Day 7 mtrs: 2.5
    :
    : Press any to continue
    :
    : write a function to load the 7 days Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant in the array.
    : loadarray(swell_size,MAXDAYS);
    :
    :
    : if the user chooses option 2, the program will analyse the Swell Size data and display the results using the following layout:
    :
    :
    :
    :
    :
    : SWELL SIZE FOR WEEK
    : --------------------------------------
    :
    : Day mtrs
    : 1 0.5
    : 2 1.0
    : 3 1.5
    : 4 0.0
    : 5 4.0
    : 6 2.0
    : 7 2.5
    :
    : total mtrs : 11.5
    : average mtrs : 1.6
    : minimum mtrs : 0.0
    : maximum mtrs : 4.0
    :
    : Press any to continue
    :
    :
    : assume that the user always runs option 1 beforerunning option 2. you do not need to write error checking for this.
    :
    : write a function to display the 7 Swell Size figures. it should accept 2 parameters, the array name and the number of itens in the array. it should display the 7 Swell Size figures as shown above. in the following example, swell_size is the array name and MAXDAYS is a constant set to the number of items in the array.
    :
    : disparray(swell_size,MAXDAYS);
    :
    : write a function to Total 7 Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant set to th numbers of items in the array.
    : sumarray(swell_size,MAXDAYS);
    :
    : write a function to determine the Minimum Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant set to th numbers of items in the array.
    : minarray(swell_size,MAXDAYS);
    :
    : write a function to determine the Maximum Swell Size figures. it should accept 2 parameters, the array name and the number of items in the array. in the following example, swell_size is the array name and MAXDAYS is a constant set to th numbers of items in the array.
    : maxarray(swell_size,MAXDAYS);
    :
    : if the user chooses option 3, the program will exit.
    :
    : for options 1 and 2, the program is to return t the menu after completing the respective tasks.
    :
    : you are design the program using structure diagrams.
    :
    : create a test plan for your application based on the specification.
    :
    : **********************************************************************
    :
    : here is ans..which i write
    :
    : /*
    : -----------------------------------------------
    : Auther : Prati
    : Created:
    : Purpose:
    : Amended:
    : ----------------------------------------------
    : */
    :
    : //--- include header files -------------------
    :
    : #include // stream I/O (cout, endll etc.)
    : #include // operating system console I/O routines
    : #include // stream I/O manipulators
    :
    : //--- main program-----------------------------------
    : void main()
    : { // main program starts
    :
    : // declare constants
    : const int MAXDAYS = 7;
    :
    : // declare variables
    : int count; // loop control variable
    : float total; //
    : float average; //
    : float minimum; // minimum sale
    : float maximum; // maximum sale
    :
    : // declare monthly sales array
    : float swell_size[MAXDAYS];
    :
    : // declare title
    : clrscr();
    : cout << "SWELL SIZE ANALYSIS PROGRAM" << endl;
    : cout << "===========================" << endl;
    : cout << endl;
    :
    : // prompt for and get each month sales
    : for(count=0;count<MAXDAYS;count++)
    : {
    : cout << "Enter Day " << (count+1) << " mtrs: ";
    : cin >> swell_size[count];
    : }
    : cout << endl;
    :
    : // display report headings
    : clrscr(); // clear screen
    : cout << "SWELL SIZE FOR WEEK" << endl;
    : cout << "-------------------" << endl;
    : cout << setiosflags(ios::right)
    : << setw(5) << "Enter Day 1 mtrs"
    : << setw(10) << ":"
    : << endl;
    :
    : // display sales for each month
    : count=0; // initialise loop counter
    : while(count<MAXDAYS) // while loop starts
    : {
    : cout << setiosflags(ios::right)
    : << setw(5) << (count+1)
    : << setprecision(2)
    : << setiosflags(ios::fixed)
    : << setw(10) << swell_size[count]
    : << endl;
    : count = count+1; // increment loop counter
    : }
    :
    : // calculate Total, Average, Minimum and maximum
    :
    : count=0; // initialise loop counter
    : total=0.0; // initialise total
    : average=0.0; // initialise average
    : minimum=swell_size[0]; // initialise minimum to first array element
    : maximum=swell_size[0]; // initialese maximum to first array element
    :
    : // loop through total
    : do
    : {
    : // accumulate total
    : total = total+swell_size[count];
    :
    : // check for new minimum
    : if (swell_size[count]<minimum)
    : {
    : minimum = swell_size[count]; // new minimum
    : }
    :
    : // check for new maximum
    : if (swell_size[count]>maximum)
    : {
    : maximum = swell_size[count]; // new maximum
    : }
    : count = count+1; // increment loop counter
    : }
    : while (count<MAXDAYS); // loop ends
    :
    : // calculate average
    : average = total/count;
    :
    : // display sales Analysis
    : cout << endl << endl;
    :
    : cout << "Total $ " << total << endl;
    : cout << "Average $ " << average << endl;
    : cout << "Minimum $ " << minimum << endl;
    : cout << "Maximum $ " << maximum << endl << endl;
    :
    : // display end of program
    : cout << "End of Program" << endl << endl;
    : cout << "Press any key to continue...";
    : getch();
    :
    : } // main program ends
    :
    : ******************************************************************
    :
    : hope to receive any ans soon...
    : thanks
    : bye
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion