Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the purpose of this assignment is to demonstrate how to design a class when given a diagram of the specification and implementation details, how to

the purpose of this assignment is to demonstrate how to design a class when given a diagram of the specification and implementation details, how to split the specification and implementation into different files, and how to use objects as array elements and pass the array to a function. Along with these assignment instructions you should find a UML diagram outlining the class members, and a presentation outlining the steps needed to add the implementation and specification (.h and .cpp) files where the class will be declared and defined. Objectives 1. Demonstrate how to write a class according to UML Diagram specifications. 2 Demonstrate the separation of class specification and implementation into separate files. 3 Demonstrate how to define and use an array with objects as array elements.4 Demonstrate how to declare, call, and define a function with an array of objects as a function parameter

For this assignment, you will need to define a class that encapsulates a single days weather information based on the UML diagram provided.The diagram specifies data members, constructors, and function members.Included is a list of implementation details for defining the constructors and function members.

Once you have written, compiled, and tested your class, you begin writing the main program(client code) that will define and use an array of these objects I recommend starting with new empty project to focus first on completing the WeatherInfo class requirements along with a temporary test program to make sure the constructors and function members all work correctly.For example, create one object using the constructor with no arguments and use it to test all the transformer (setXXX) member functions and print it with the toString() member function.Then create another object using the constructor with arguments and use that one to print its values by calling all the observer (getXXX)member functions.Once you are satisfied the class is implemented properly,exclude the test program from Solution Explorer keeping only the WeatherInfo.h and WeatherInfo.cpp files, and then add a new .cpp file to the project for completing the assignment(Add |New).Requirements 1.Follow the UML diagram specifications and implementation details.2 The specifications for the WeatherInfo class should be placed in a header (WeatherInfo.h) file where you define that class with data and function member declarations only. 3 The constructor and function member definitions for the WeatherInfo class should be placed in an implementation (WeatherInfo.cpp) file. 4 In the programs main() function, define a single 1-dimensional array of size 7 defined using type WeatherInfo to hold data for at most 7 days of weather information.5 Use a DO-WHILE loop to input data for creating objects and storing them in the array. 6 Demonstrate how to declare, call, and define a function where you pass the array and day counter to that function, and that uses a FOR loop to print the list of weather information. 7. Declare, call, and define 3 value-returning functions in your main program named indexOfHightestTemp indexOfLowestTemp, and totalRainFall. The first one should find and return the array location (index) of the highest temperature, and the second one should find and return the array location for the lowest temperature. The last one should find and return the total rainfall. The main program calls these functions to get those values and then print the reading and day for the highest and lowest temperatures, and the total rain fall. 8 Declare, call, and define 2 more value returning functions in your main program named averageHigh and averageLow. The first one should find and return the average high temperature, and the second one should find and return the average low temperature. The main program calls these functions to get those values and then print them at the bottom of the list under those columns of output. Also, calculate and print the average rain fall sinceyou already should have that total handy. 9 Declare, call, and define a function named userInput. Modify the program as necessary to move the input DO-WHILE loop into that function. This will need to be a value-returning function and should return the day count incremented by the loop back to main since other functions (and loops) will need to know that counter value. This function also will need the array and size passed in as parameters since it will be getting filled with objects created from user input.10 Run your program twice testing that it works with a partially-filled array (only 5 days input) and also with a completely filled array (all 7 days input).Considerations:You may need to include string and using namespace std; in your WeatherInfo.h file.You will need to include sstream and possibly iomanip in your WeatherInfo.cpp file. Because the string header and namespaceare already included in WeatherInfo.h, you should not need to add them in this file, but you can if you want to. You will need to add include WeatherInfo.h in any file that uses the WeatherInfoclass declarations, for example in the source code (.cpp) file where you define the main() function

.You can use a temporary WeatherInfo object in the input loop while storing objects in the array.

For example, define and use variables to read the week day high temperature,low temperaturand rain fall

from the user , you then use those variables to declare a temporary WeatherInfo object and assign it to the next array element: WeatherInfo temp(weekDay,highTemp,lowTemp,rainFall); week[dayCount] = temp;

Or you can simply use the constructor by itself to assign an object directly to the array elements:week[dayCount] =

WeatherInfo(weekDay, highTemp, lowTemp, rainFall);When defining the toString()function member, refer to the Employee.cpp example (lab exercise) demonstrating how to do this with numeric types using an ostringstream output object, which is an output string stream that formats an output string in memory.You will need to include the sstream library header in order to declare one of these objects in a function, and include iomanip if you want to use setw() and precision() manipulators. Then you can use basically the same formatting including setw() , precision() fixed , and showpoint that weve used elsewhere to format a line of output for the weather information list.

You even can insert endl manipulators into the string but always should use one last ends manipulator (meaning endstring) to mark the end of the string that is being formatted in memory; otherwise your output could print garbage at the end of the string.Defining a function like this will allow you to simplify the code in the rest of the program

by just calling the toString() function for each array element, and if the formatted string prints onone line (no endl inserted into the string by the function) then you can adjust the overall width as necessary:cout

Sample user input with interactive prompts:

Enter day of week (eg. Sunday, Monday, etc...): Sunday

Enter high temperature in degrees Fahr: 38

Enter low temperature in degrees

Fahr: 26

Enter total rainfall in inches: 1.0

Another day (y or n): y

Enter day of week (eg. Sunday, Monday, etc...): Monday

Enter high temperature in degrees Fahr: 35

Enter low temperature in degrees Fahr: 20

Enter total rainfall in inches: 0.0

Another

day (y or n): y

etc . . .

etc . . .

etc . . .

Another day (y or n): y

Enter day of week (eg. Sunday, Monday, etc...): Friday

Enter high temperature in degrees Fahr: 38

Enter low temperature in degrees Fahr: 32

Enter total rainfall in inches: 1.2

Another day (y or n): y

Enter day of week (eg. Sunday, Monday, etc...): Saturday

Enter high temperature in degrees Fahr: 40

Enter low temperature in degrees Fahr: 35

Enter total rainfall in inches: 1.8

Sample

required

program output (completely

filled array):

Week Day Hi Low Rain

--------

----

----

----

Sunday 38 26 1.0

Monday 35 20 0.0

Tuesday 34 19 0.0

Wednesday 36 25 0.0

Thursday 38 27 0.5

Friday 3

9

32 1.2

Saturday 40 35 1.8

--------

----

----

----

Averages 37.1

26.3 0.6

Highest reading: 40 [Saturday]

Lowest reading: 19 [Tuesday]

Total

rainfall: 4.5"

Sample

required

program output (partially filled array):

Week Day Hi Low Rain

--------

----

----

----

Monday 35 20 0.0

Tuesday 34 19 0.0

Wednesday 36 25 0.0

Thursday 38 27 0.5

Friday 3

9

32 1.2

---------

----

----

----

Averages 36.

4

24.6 0.3

Highest reading: 39

[

Friday]

Lowest reading:

19

[Tuesday]

Total rainfall: 1.7image text in transcribed

UML Diagram Specification for Weatherlnfo class WeatherInfo - weekDay string highTemp : int - lowTemp int - rainFall double + WeatherInfo () + WeatherInfo (day:string, hi:int, lo:int, rain:double) + getwekDay Ostring + getHighTemp () : int + getLowTemp) : int + getRainFall double + setwekDay (day:string) : void + setHighTemp (degrees:int): void + setLowTemp (degrees:int) : void + setRainFall (inches:double) : void + tostring) : string Implementation Details Constructors: Initialize a Weatherlnfo object to default values using zero for numeric types and empty string for string type, or Initialize a Weatherlnfo object using constructor parameter values Observers (getXxx accessor functions): Return requested data member value Transformers (setXxx mutator functions): Assign parameter value to requested data member Additional observer function members: Return formatted string representation of weather data members including week day, high temp, low temp, and rain fall Include decimal formatting for rain fall (e.g. fixed decimal point, always show decimal poin, 1-digit precision o

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

how man many hydrogens are in the compound shown below

Answered: 1 week ago

Question

What is the equation of the circuit . ? N F

Answered: 1 week ago

Question

Identify cultural barriers to communication.

Answered: 1 week ago