How well your function handles error situations

Assignment Help Computer Engineering
Reference no: EM131270270

Simple Translation Dictionary

We want to implement a program which will help students learn the vocabulary of foreign languages. The first step, which has been assigned to you, is to build a data structure representing a list of English words and their translation in a foreign language.

We'll also need to provide functions allowing us to lookup translations from English-toForeign And Foreign-to-English.

The main data structure of this program encapsulates some variables specifying the maximal and current number of words in the dictionary along with a pointer to a dynamically allocated array of pointers on another data structure representing a pair of words.

A skeleton for this project is provided to you along with the struct definitions.

Files you will be working with

You will be provided with several files to get you started working on this assignment.

- You must not alter the file names, remove or add files to the project
- You must only modify the ones marked below with a yes in "Modify it?"
- You must not insert any comments or code in the tests.c file which, when read by another student, would give them any insights about the solutions you implemented in tools.c.

Important Academic Honesty Note;

The role of tests.c is to allow you to test your program to verify it adheres to requirements. Your instructor might allow you to exchange this file, and this file only, with other students. Therefore, you must uphold academic honesty standards by not inserting any information, besides the tests, which would divulge your design or implementation of the solutions to another student. Failure to do so will earn you a FF for the offering.

Here are the files;

File name Modify it? Role
tools.c
Yes

Implementation of your solution to the assignment
tests.c
Yes

Implementation of your test functions
tools.h
No

Header file for tools.c
main.c
No

Implementation of the main function starting your tests
testlib.h
No

Definition of the TEST function you must use in your tests
testlib.c
No

Implementation of the above

Task #1 - Implement and test dictionary_build

This first function, which you will implement in tools.c, will be used every time you need to start working on a new dictionary. Part of your grade on this implementation will be on how well your function handles error situations; e.g. we ask for a dictionary of negative size, there is no memory available for your malloc.

Any time you encounter one of these, or similar, errors, you should return a specific value from your function which is described in the program's source itself. When you test your function with such parameters, you should verify its return value is appropriate.

Make sure you follow our usual process when working on this function;

- Read the requirements & existing source thoroughly
- Implement your tests based on how you understand the requirements. This time you will note that we are not providing tests at all. Part of your work is to leverage what you learned in the previous PAs to design & implement your own tests
- Implement the function dictionary_build
- Update your tests based on what you learned
- Refactor your solution before to go to the next task.

Task #2 - Implement and test dictionary_free

This 2 function will be used to de-allocate a dictionary. Here are some things to keep in mind;

- Make sure you dispose of all the memory you allocated in a struct dictionary.

Drawing a diagram of the data structures will help you figure out what you are deallocating as you write your dictionary_free function. This should help you avoid memory leaks.

- If the dictionary passed to your function is only partially allocated - e.g. due to a bug elsewhere - you should handle it gracefully; i.e. before to free a pointer, make sure it is not NULL.

Follow the steps outlined in task#1 as you work on implementing this task. Again, the source code provides you with most of the information you need in the form of comments and the code itself.

Task #3 - Implement and test dictionary_add

The 3rd function will take a dictionary and two strings as parameters. It will use strdup to make a copy of the words provided as parameters and insert them as a new element in the dictionary.

Again, detect possible bad parameters; e.g. no words provided; 1 word instead of 2... and verify the return value is appropriate based on the documentation in the program itself.

Follow the steps outlined in task#1 as you work on implementing this task.

Task #4 - Implement and test dictionary_translate

This function, as indicated in its comments, will return a strdup copy of the translation of one of the two strings passed as parameter. It is expected that one will use this function with a valid dictionary, and specify one of the two strings to be NULL.

- If the English word parameter is NULL, we are providing a string in the foreign language to be translated into English.
- If the foreign word is NULL, we do the opposite.

Passing two non-NULL strings or a NULL dictionary are errors which should be handled by your function returning the value described in the documentation in the program itself.

Follow the steps outlined in task#1 as you work on implementing this task.

Reference no: EM131270270

Questions Cloud

Find the marginal productivity of labor : If the company is now using 250 units of labor and 125 units of capital, find the marginal productivity of labor and the marginal productivity of capital.
Mentoring programs for women and minorities : There have been many discussions recently regarding how more women and minorities can break through the glass ceiling. Data suggests these groups are underrepresented in the top echelons of organizations. Several reasons for this have been well docum..
Microeconomic problem and a macroeconomic problem : What is an example of a microeconomic problem and a macroeconomic problem?
Describe resources of architectural engineering design firm : M2A1: Case Analysis: Comprehensive Questions - List, describe, and compare at least 10 constraints lifted and at least 10 constraints imposed on the vehicle when changing from a gasoline engine to an electric-gasoline engine
How well your function handles error situations : This first function, which you will implement in tools.c, will be used every time you need to start working on a new dictionary. Part of your grade on this implementation will be on how well your function handles error situations.
Unplanned inventory investment equals : Assume a closed economy with no government. Suppose that autonomous consumption equals $400, planned investment equals $500, and the mpc equals 0.9. 1. Using the information in Situation 20-1, if aggregate output is equal to $10,000, then unplanned..
State is comprised of mostly rural areas : You are the Director of Public Health for your state.(Any state) Your state is comprised of mostly rural areas. These rural areas do not have access to many state resources, especially in terms of medical care. As a director, it is your job to come u..
Were there any components that were not entirely clear : In order to ensure your viewers experience the full effect of your mock proposal, it is imperative that your voice and a visual presentation complement each other as you explain all nine of its components. Therefore, it is a requirement you inclu..
Write boolean equations for the next state and output : Describe in words what the state machine in Figure 3.69 does. Using binary state encodings, complete a state transition table and output table for the FSM. Write Boolean equations for the next state and output and sketch a schematic of the FSM.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Questioncreate a scheme for vb mail order to maintain a

questioncreate a scheme for vb mail order to maintain a list of catalogs. utilize a drop-down combo box for

  How many ways a committee of 4 people can be choosen

The question of how various ways a committee of 4 people can be selected from a group of 10 is known as a combination. The notation in general for counting the number of ways of selecting r items from a group of n is C(n,r) = n! / r!(n-r)!

  Design a class named productionworker

The workday is divided into two shifts: day and night. The shift field will hold an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. make the appropriate accessor and mutator met..

  Developing the flowchart using visual logic

Develop a flowchart by using the Visual Logic for a program which accepts a candy name.

  How to increment value in one cell

For example, I have cell A that has values such as 1, 2, 3, 4 etc...but I want to be able to check cell A and if there is a value present, increment cell B by 1 each time. I would like a macro to do this or formula.

  Provide the corresponding memory snapshot

Provide the corresponding memory snapshot, and the value of the stream state flags, after each of the subsequent sets of statements is executed:

  Create a structure student containing character array

Create a structure STUDENT containing character array firstName[30], character array lastName[30], integer SID, integer array with 4 scores.

  Network that contains several netware 4.11 servers

Your company has a network that contains several NetWare 4.11 servers and uses IPX as the routing protocol. Each of the network segments has as a minimum  one NetWare server on it. Which of the following responds to a Get Nearest Server (GNS) reque..

  The c++ libraries on strings have many functions

The C++ libraries on strings have many functions that can be used to handle various string operations. Write a function called stringlast that can be used to find the last n characters in a string and return a pointer to this new string

  How might a systems analyst approach the problem

Since software controls substation operations, how might a systems analyst approach this problem as a systems project? Are there special considerations that a systems analyst needs to think about when dealing with real-time systems?

  Prove that binary search over a sorted array of n elements

Prove that binary search over a sorted array of N elements operates in logarithmic time. (i.e. O(log2(N))

  Provide a polynomial-time transformation

provide a polynomial-time transformation of any instance (G, k) of CLIQUE into an instance (G', p, q) of DENSE SUBGRAPH such that G has a clique of size k if and only if G' has p vertices with at least q edges between them.

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