Starting from:
$26.99

$20.99

Lab Task #3 Solution

The aim of this lab is to provide you with some experience in writing programs using binary files.  You will also gain some experience working with makefile.

 
 

TASK 1:

 

You are provided with a text file (chemicalElements.txt) containing a list of chemical elements. Each line on the text file will contain the atomic mass, followed by the element name, chemical symbol, and an integer atomic number. Example of a few lines from the file is as follows:

 

 

1.0079  Hydrogen          H          1

4.0026  Helium              He        2

6.941    Lithium              Li          3

 

Your task is to read the information for each of the element in this file and produce a binary file containing records of these chemical elements. Each record should be stored in a struct variable declared as:

 

struct ChemicalElement

{

     int atomicNumber;

     char name[100];

     char symbol[3];

     float mass;

};

 

Once the binary file has been created, allow the user to perform a search on the binary file by providing the element name or symbol (display all the details if found), display all the chemical elements’ details that have atomic mass greater than a given value, or display the details of all the chemical elements with the atomic number in between two given values. The details of the chemical element will then be displayed on standard output.

 

Separate function should be written to:

1.      Read records from the text file and write to binary file.

2.      Search by name or symbol

3.      Display data with atomic mass greater than the value passed to it

4.      Display data between two given atomic number

Function 1 be written in a file named fileOperation.cpp and functions 2, 3 & 4 should be written in a file named chemical.cpp. Create suitable interface file for each of the implementation file stated earlier.  All functions should be called from main(). The main() function should be written in a separate file named main.cpp.

 

 

 

 

 

TASK 2:

 

Your second task is to write a suitable makefile for the application done in Task 1.  The makefile should be written to create an executable named prog. Include also a clean target in your makefile to remove all the targets created earlier.

 

Test your makefile with no targets created at the beginning and observe the compilation process done. Then make some changes in one of the implementation file above.  You can do this by simply adding a cout statement. Then run the makefile again and observe the difference between this compilation process and the previous one. Write down your findings in a text file by including the screen shot of the terminal screen when you run your makefile,  and submit this together with your makefile.

 

 


More products