logo

Crowdly

Browser

Add to Chrome

 Exercise L9.E2 You are provided with a file named contamination_analysis.tx...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

 Exercise L9.E2

You are provided with a file named contamination_analysis.txt. This file contains details regarding a contamination analysis ( The process of finding unwanted chemical compounds in a certain material) carried out for a set of chemicals by a lab. 

A set of chemical names and the molecular structure of the contaminant in each chemical is given in the file. 

Example input file (contamination_analysis.txt) :

ABC/D/12    C6-H5-Cl3-Na

DE/W/45     C7-S-O4-Na

MLI/85/9    C6-H6-S-O3-Mg

QT/36/X     C4-Cl3-O3-Cl3-O2

AL/2T/B     C2-N-H4-Na

PP/L2/28    C6-S-O8-Na-H2-Cl3

  • Each line of the input file has a chemical name and the molecular formula of the contaminant found in the chemical ( ABC/D/12 is the chemical name, and C6-H5-Cl3-Na is the molecular formula for the contaminant in the chemical ABC/D/12 ).

  • The number of chemicals in an input file can vary. The example input file has details regarding 6 chemicals but the input files in test cases can have up to 10 chemicals in a file.

You need to categorize each chemical in the input files based on the contaminant  in the chemical. The following criteria should be followed for categorizing chemicals.

Criteria:

  1. The chemical is categorized as ‘Level_1’ if the contaminant contains;

                  a. One  ‘S’ molecule and,

                  b. Four ‘O’ molecules and,

                  c. One ‘Na’ molecule 

  1. The chemical is categorized as ‘Level_2’ if the contaminant contains;

                  a. One  ‘S’ molecule and,

                  b. Three ‘O’ molecules and,

                  c. One ‘Mg’ molecule 

       3.The chemical is categorized as ‘Level_3’ if the contaminant contains;

                  a. Two  ‘O’ molecules and,

                  b. Three ‘Cl’ molecules 

        4. If any contaminant belongs to more than one category above then the chemical is  categorized as ‘Level_4’.

        5.If the contaminant doesn’t belong to any of the above categories then the chemical is categorized as ‘Level_0.txt’.

Note : When categorizing, give priority to the order of the criteria.

Ex: If the contaminant has (C6-S-O3-Na-O2-Mg)

  • One ‘S’
  • Six ‘C’ s
  • Five ‘O’ s
  • One ‘Na’
  • One ‘Mg’

Then the category is Level_1. Because after we categorized it to Level_1 the left molecules are

  • Six ‘C’ s
  • One ‘O’
  • One ‘Mg'
The leftover molecules cannot form Level_2.

Please submit the flowchart diagram that illustrates the algorithm of your program here.

More questions like this

Want instant access to all verified answers on online.uom.lk?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome