Define a structure type

Assignment Help Data Structure & Algorithms
Reference no: EM13762928

Your program must meet the following requirements:

1. Define a structure type to represent a single CD. The year must be stored as an integer, all other fields should be strings. Because memory space will be an issue you may not assume a length for the string fields, but must dynamically allocate appropriately sized strings as needed.

2. Write a function that takes a CD handle (i.e., a pointer to a pointer) and a file pointer as arguments. The file pointer should point to a file of CDs formatted as described above. The function should do the following (not necessarily in this order):
- allocate a CD for the handle to refer to
- read the next line from the specified file pointer using fgets
- use strtok and sscanf to parse the input line into the CD fields

As mentioned above, you must dynamically allocate the string fields in the CD to be exactly large enough to hold the corresponding strings. You may assume that an input line is at most 256 characters.

The function should return 0 if successful, 1 if an error occurred in parsing the line, and EOF if end-of-file was encountered.

3. Write a function that takes a CD handle argument. The function should deallocate all dynamically allocated memory associated with the CD (including the CD itself). The CD address should be set to NULL.

4. Write a function that takes a CD argument and prints out the CD to stdout in the following format (using the first CD in cds.db as an example):

The CD Astral Weeks was released by Morrison, Van in 1968 on Warner Bros.
page 1 of 2

5. Write a function that takes takes two arguments: a CD and the name of an artist. The function should return whether or not the specified CD was recorded by the indicated artist.

6. Now write a main function that takes two command-line arguments: the name of the input CD file and the name of an artist. Your main should do the following:

a. Open the indicated CD input file for reading.

b. Repeat the following for all CDs in the input file (i.e., until EOF is encountered in the
first step):

i. Use your function 2 to dynamically allocate and read-in a single CD. If your function indicates that an error has occurred in reading the CD then output an error message and exit the program.
ii. Use your function 5 to check if the CD was recorded by the artist indicated in the second command-line argument. If it was, print-out the CD using your function 4.
iii. Deallocate the CD using your function 3.

Reference no: EM13762928

Questions Cloud

Consumer sentiments in a positive direction : Do you know what are some active ways the government tries to turn consumer sentiments in a positive direction when the forecast on the news and in the actual economy looks bleak?
Assume no other income and taxes during retirement : Amanda is expected to receive full social security retirement benefit of $15500 annually when she turns 65. These benefits can be increased by 40% if she delays taking them till age 70. If her life expectancy is 90 years and expected rate of return i..
Excel for decision support modeling : Willy Wonka is considering starting a production line to produce fizzy lifting drinks. As Chief Oompa Loompa (COL) you have access to a wide variety of financial data to help you determine whether bringing the new production line on will be a sma..
Program takes input from a user in the form of a phrase : This program takes input from a user in the form of a phrase. It then converts the phrase to ig latin.
Define a structure type : Define a structure type to represent a single CD. The year must be stored as an integer, all other fields should be strings. Because memory space will be an issue you may not assume a length for the string fields, but must dynamically allocate app..
Leverage measure and about common stock : Which one of the following statements about common stock is true? Substituting EBITDA for EBIT when computing the times interest earned ratio will make the company appear. Which one of the following is a leverage measure?
Current labor cost per car sold : Suppose that a car dealership wishes to see if efficiency wages will help improve its salespeople's productivity. Currently, each salesperson sells an average of one car per day while being paid $20 per hour for an eight-hour day.
The causes of nursing home death : What are some of the causes of nursing home deaths?
Compute the combined worth of steves retirement assets : Steve is about to retire and wants to calculate the total worth of his retirement assets. He has a corporate pension paying $2250 at the beginning of every month. He is also entitled for Social Security benefits of $1450 at the beginning of every mon..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Define wan and provide an example of typical wan setup

Define a WAN and provide an example of a typical WAN setup and describe the components. Provide a picture, chart, or image if possible.

  Design time randomized monte carlo algorithm

You have to design an O(n) time randomized Monte Carlo algorithm which computes an (1 + o)- approximate ham-sandwich cut with probability 1 - n-c for any given constant c > 0.

  Calculate bits number output of first round-des decryption

Calculate the bits number 1, 16, 33, and 48 at output of first round of DES decryption, suppose that ciphertext block is composed of all ones

  Write a program that reads a file and builds a linked list

Write a program that reads a file and builds a linked list. After the list is built display it on monitor. You may use any appropriate data structure, but it should have a key field and data. Two possibilities are a list of your favourite CD's or ..

  Students will create code to implement a hash algorithm and

students will create code to implement a hash algorithm and solution by addressing the followingcreate a flowchart to

  Convert the following formulas from reverse polish to infix

Convert the following formulas from reverse Polish to infix.

  Implement a state-space search

You will implement a state-space search that will find a solution to the sixteenpuzzle. For this program, in addition to the state-space search control, you will need to implement at least two other classes

  Developing an eer model

Construct an EER model for the given situation using the traditional EER notation, the Visio notation or the supertypes notation.

  Creating asp.net project with visual studio.net

Design an ASP.NET assignment with Visual Studio.NET 2005. Add an aspx form to the application. Place a ListBox control, a TextBox control and a Button control on the form.

  Find smallest element and its index

Write a C++ program that inputs 10 integers into an array and displays the inputs, the smallest element and its index

  What is difference between serial and sequential searching

What is the difference between serial, sequential and indexed sequential searching

  Using a backtracking algorithm

If the backtracking algorithm finds a dead end, it retraces its path until it reaches a position from which there is an untried path. The backtracking algorithm always tries all directions from any position, and always in the same order.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd