Question
Please code the following in C language. Thank you. For any given state/city, there may be many lines in the file. The lines towards the
Please code the following in C language. Thank you.
For any given state/city, there may be many lines in the file. The lines towards the bottom of the file represent the most recent temperatures. Write a program which does the following:
1. Prompts the user to enter the name of the input file; if the user does not enter a name, use a default file name, such as temperatures.txt
2. Reads the data from file into an ordered list of stacks. The list is sorted in ascending order by the state/city string, a unique key. The temperature values for a given state/city are pushed onto its stack. (See example below).
The stack nodes contain - an integer (temperature) and - a pointer to the next stack node.
The list nodes contain
- a state/city string,
- a pointer to the next state/city node, - a pointer to the previous state/city node, - a pointer to the stack of temperature nodes for that
state/city, - a count of the nodes in the stack, and
Requirement: create a circular doubly-linked list with one sentinel node
3. Displays the sorted list in ascending order (state/city and only one temperature value at the top of the stack. (A Z)
4. Displays the sorted list in descending order (state/city and only one temperature value at the top of the stack. (Z A).
5. Search loop. Prompts the user for a state/city string. If the state/city string is in the list, display the most recent temperature and the average temperature for that state/city. Give an error message if the state/city string is not found in the list. Prompts the user repeatedly until s/he enters quit.
INPUT FILE: temperature.txt
Pennsylvania,Philadelphia:91
California,San Francisco:75
Nevada,Reno:108
Arizona,Flagstaff:81
California,Yreka:101
Arizona,Tucson:107
California,Los Angeles:78
California,Los Angeles:81
Pennsylvania,Pittsburgh:89
Oregon,Salem:90
California,Los Angeles:82
Arizona,Flagstaff:84
California,San Francisco:64
Oregon,Salem:83
California,San Francisco:68
Arizona,Tucson:99
California,Yreka:100
Arizona,Phoenix:109
Oregon,Portland:82
Arizona,Tucson:103
Oregon,Portland:79
Arizona,Phoenix:107
California,Cupertino:88
Oregon,Salem:85
Pennsylvania,Philadelphia:86
California,Los Angeles:97
Nevada,Reno:108
#include
#include
#include
#ifdef _MSC_VER
#include
#endif
int main( void )
{
#ifdef _MSC_VER
printf( _CrtDumpMemoryLeaks() ? "Memory Leak " : "No Memory Leak ");
#endif
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started