Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; // Constant for the number of months const int NUM_MONTHS = 12; // Function prototypes double getTotal(double [], int); double

#include #include using namespace std;

// Constant for the number of months const int NUM_MONTHS = 12;

// Function prototypes double getTotal(double [], int); double getAverage(double [], int); double getLargest(double [], int, int &); double getSmallest(double [], int, int &);

int main() { // Array to hold the rainfall data double rainFall[NUM_MONTHS];

// Get the rainfall for each month. for (int month = 0; month > rainFall[month]; // Validate the value entered. while (rainFall[month] > rainFall[month]; } } // Set the numeric output formatting. cout

// Now display the largest & smallest amounts. // The subscript variable will be passed by reference // the the getLargest and getSmallets functions. int subScript;

// Display the largest amount of rainfall. cout

// Display the smallest amount of rainfall. cout

return 0; }

// ******************************************************** // The getTotal function calculates and returns the * // total of the values stored in the array parameter. * // The size parameter indicates the number of elements * // in the array. * // ******************************************************** double getTotal(double values[], int size) { double total = 0.0; // Accumulator

// Step through the array and add each value // to the total variable. for (int count = 0; count

return total; }

// ******************************************************** // The getAverage function returns the average of the * // values in the array parameter. The size parameter * // indicates the number of elements in the array. * // ******************************************************** double getAverage(double values[], int size) { // Simpy get the total of the array values // and divide by the number of elements. double average = getTotal(values, size) / size; return average; }

// ******************************************************** // The getLargest function returns the smallest value in * // the array parameter, and stores the subscript of the * // largest value in the element reference parameter. * // ******************************************************** double getLargest(double values[], int size, int &element) { double largest; // To hold the largest value. // Assume element 0 holds the largest value. largest = values[0]; element = 0; // Compare the value in largest to all the // other values in the array. for (int count = 1; count largest) { largest = values[count]; element = count; } }

return largest; }

// ******************************************************** // The getSmallest function returns the smallest value in * // the array parameter, and stores the subscript of the * // smallest value in the element reference parameter. * // ******************************************************** double getSmallest(double values[], int size, int &element) { double smallest; // To hold the smallest value // Assume element 0 holds the smallest value. smallest = values[0]; element = 0; // Compare the value in largest to all the // other values in the array. for (int count = 1; count

image text in transcribed

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
1. Download the file Linkedlist.h. Check the file and write the missing function definitions as indicated. Function headers are already included. T get Total(); int numNodes(); T getAverage (); T getLargest(); int get Largest Position(); Tget Smallest(); int get Smallest Position(); 2. Download the file rainfall.cpp. This program lets the user enter the total rainfall for each of 12 months into an array then display statistical information. Modify the program so that it uses LinkedList.h, instead of an array to hold the monthly data. 3. Using LinkedList.h, write a driver program (mainFiles.cpp) that defines an integer list and a string list. After creating the two lists, use the input from intData.dat and strData.dat files to insert data into the linked lists. These files have one data item per line. Insert the data items to their respective list objects. Display the lists. Use the search function provided by the class to look for certain items in the lists. The intSearch.dat and strSearch.dat files have one data item per line. Search the respective lists for each data item in these files. Your program should display whether or not the item is found in the list. For example, if your integer list object contains 4, 19, and 25 and the search file contains 8 and 25, your program should output: 8 was NOT found in the list 25 was found in the list Same for the string items. #lthaer LINKEDLIST_H #define LINKEDLIST_H #include using namespace std; template class LinkedList private: // Declare a structure for the list struct ListNode T value; struct ListNode *next; ListNode *head; // List head pointer public: LinkedList() // Constructor { head = nullptr; } ~LinkedList(); // Destructor void appendNode(T); void insertNode(T); void delete Node(T); void displayList(); int search(T); // search function T getTotal(); int numNodes(); T getAverage(); T getLargest(); int getLargestPosition(); T getSmallest(); int getSmallestPosition(); template void LinkedList:appendNode(T newValue) ListNode *newNode, *nodePtr = nullptr; newNode = new ListNode; newNode->value = newValue; newNode->next = nullptr; if (!head) head = newNode; else // Otherwise, insert newNode at end nodePtr = head; while (nodePtr->next) nodePtr = nodePtr->next; node Ptr->next = newNode; template void LinkedList::displayList() ListNode *nodePtr = nullptr; nodePtr = head; while (nodePtr) cout value next; template void LinkedList::insertNode(T newValue), ListNode *newNode, *nodePtr, *previousNode = nullptr; newNode = new ListNode; newNode->value = newValue; if (!head) head = newNode; newNode->next = nullptr; else // Otherwise, insert newNode nodePtr = head; previousNode = nullptr; while (nodePtr != nullptr && nodePtr->value next; if (previousNode == nullptr) head = newNode; newNode->next = nodePtr; else // Otherwise, insert it after the prev. node. previousNode->next = newNode; newNode->next = nodePtr; template void LinkedList::delete Node(T searchvalue) ListNode *nodePtr, *previousNode = nullptr; if (!head) return; if (head->value == search Value) nodePtr = head->next; delete head; head = nodePtr; else nodePtr = head; while (nodePtr != nullptr && nodePtr->value != searchValue) previousNode = nodePtr; nodePtr = nodePtr->next; if (nodePtr) previousNode->next = nodePtr->next; delete nodePtr; template LinkedList::~LinkedList() ListNode *nodePtr, *nextNode = nullptr; nodePtr = head; while (nodePtr != nullptr) nextNode = nodePtr->next; delete nodePtr; nodePtr = nextNode; template int LinkedList::search(T val) int count = 1; ListNode *nodePtr = nullptr; nodePtr = head; while (nodePtr) if( nodePtr->value == val) return count; else nodePtr = nodePtr->next; count++; return 0; template T LinkedList::getTotal() // write the function definition template int LinkedList::num Nodes() // write the function definition template T LinkedList::getAverage() T LinkedList::getAverage() // write the function definition template T LinkedList::getLargest() [/write the function definition template int LinkedList::getLargestPosition() // write the function definition return position; template T LinkedList::getSmallest() // write the function definition template int LinkedList::getSmallestPosition() [/write the function definition #endif

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

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

Please make it fast 8 4 1 . .

Answered: 1 week ago

Question

What has been your desire for leadership in CVS Health?

Answered: 1 week ago

Question

Question 5) Let n = N and Y Answered: 1 week ago

Answered: 1 week ago

Question

1. Is it a topic you are interested in and know something about?

Answered: 1 week ago