Question

4. Now consider a set of stock records. A stock record consists of a stock code...

4. Now consider a set of stock records. A stock record consists of a stock code which is a null-terminated string of three uppercase letters (e.g., "APL"), a price which is a positive real number (e.g., 22.0), and a predicted profit which is also a positive real number (e.g., 148.9)

4.1 [4 marks] Write the definition of a struct type named stock_t to represent a stock record as described above.

4.2 [5 marks] Write a function int stock_cmp(void *stock1, void *stock2)

that compares two stock_t typed values pointed to by stock1 and stock2. The function should return:

• -1, if the stock record pointed to by stock1 has an alphabetically smaller stock code than that of the stock record pointed to by stock2;

• 1, if the stock record pointed to by stock1 has an alphabetically larger stock code than that of the stock record pointed to by stock2;

• 0, if the two stock records pointed to by stock1 and stock2 have the same stock code.

For example, if stock1 points to a record {"APL", 22.0, 148.9} and stock2 points to a record {"GGL", 85.3, 950.2}, the function should return -1 since "APL" < "GGL".

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ansuoer Given that, # include stdio.h 11 shuckare for stouk typede stut stuk strck- tecde 3]; of stock Lode chas loat Price P2 (one>stock- Code [J) く(twozshck-code (two-7 stoek -Code (one-stick-cade (i]) refurn1 relurnt); int main lvoid { Stock-tstok

Add a comment
Know the answer?
Add Answer to:
4. Now consider a set of stock records. A stock record consists of a stock code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the syntactically correct C code below, which is missing a function copy_positive. #include <stdio.h> /*...

    Consider the syntactically correct C code below, which is missing a function copy_positive. #include <stdio.h> /* copy_positive(A, Aout, size) * Given an array A, which will have the provided size, copy all positive * (non-negative/non-zero) elements of A into the provided output array Aout. * Return the size of the resulting array. */ /* (your code from below would be placed here) */ void print_array(int arr[], int n){ for( int i = 0; i < n; i++ ) printf("%d ",...

  • // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given...

    // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • Problem 4 (DOM operations - 30 points): Consider the Python code snippet bookstore.py for DOM operation,...

    Problem 4 (DOM operations - 30 points): Consider the Python code snippet bookstore.py for DOM operation, some basic methods and properties and an xml file on bookstore which we discussed this week. Wite two func- tions; First, write a recursive Python function get_text(elm) to extract all the text of a dom tree pointed by elm. For example, get_text(elm), where elm=<bookstore>, will return [[u'Emacs User Manual', u'Richard Stallman', u'1980', u'12.00'], [u'Timeline', u'Michael Chricton', u'1999', u'15.00'], [u'Catch 22', u'Joseph Heller', u'1961', u'20.00'],...

  • Given java code is below, please use it! import java.util.Scanner; public class LA2a {      ...

    Given java code is below, please use it! import java.util.Scanner; public class LA2a {       /**    * Number of digits in a valid value sequence    */    public static final int SEQ_DIGITS = 10;       /**    * Error for an invalid sequence    * (not correct number of characters    * or not made only of digits)    */    public static final String ERR_SEQ = "Invalid sequence";       /**    * Error for...

  • CSC151 Stock Portfolio GUI Project Goal You are to write a GUI program that will allow...

    CSC151 Stock Portfolio GUI Project Goal You are to write a GUI program that will allow a user to buy, sell and view stocks in a stock portfolio. This document will describe the minimum expected functions for a grade of 90. Your mission is to “go and do better.” You’ll find a list of enhancement options at the end of this document. Objectives By the end of this project, the student will be able to • write a GUI program...

  • // READ BEFORE YOU START: // You are given a partially completed program that creates a...

    // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...

  • can you please follow all the instructions ? The answers that I got has either missing...

    can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT