Alcohol Compositions

GauravChadha
Assignment5_F2018.pdf

Assignment 5 CS1003 Due 16th November by 4pm in D2L Assignment 5 dropbox

All assignments are to be completed individually. Any questions regarding assignments should be directed to the lab TA’s or course instructor.

The molecular weight of any compound is the sum of the products of the number of atoms of each element and the atomic weight of each element present in the compound. The names and composition of some alcohols are listed in an excel table called composition_alcohols.xlsx. The first column of the table are the atomic weights for each element that makes up the alcohol (carbon = 12, hydrogen = 1, and oxygen = 16). The remaining elements are the number of atoms of each element present in the compound. For example, Ethanol is made up of 2 carbon, 6 hydrogen, and 1 oxygen. Ask the user to enter the name of the file (they will not enter the name of the folder the file is stored in – we can assume it is always located in the Data folder. Check if the file exists – if it does not then continue to prompt the user for the name of the file either until they enter the correct file name or if they have entered the wrong file name 3 times the program terminates. Once the correct file name is entered, calculate the molecular weight of each compound and print out its weight and name in the format shown below. This program needs to be programmed in the general such that if more alcohols were to be added the program would still work correctly. Record the output (not the user input) in a text document (Molecular_Weights.txt). Make sure the diary does not append to a diary that already exists – instead make sure to check for and delete any diaries that already exist by this name before creating a new one. Make use of loops and variables! Sample Output (user input shown in bold and italics): Enter the name of the file: compositionalcohols.xlsx Invalid file name. Enter the name of the file: Data/composition_alcohols.xlsx Invalid file name. Enter the name of the file: composition_alcohols.xlsx Molecular weight of Ethanol is: 46 Molecular weight of Methanol is: 32 Molecular weight of Propane is: 60 Molecular weight of Butanol is: 74 Molecular weight of Propanol is: 60 Molecular weight of Pentanol is: 88 The alcohol with the smallest molar mass is Methanol with a mass of: 32 The alcohol with the largest molar mass is Pentanol with a mass of: 88

Sample Diary:

Molecular weight of Ethanol is: 46 Molecular weight of Methanol is: 32 Molecular weight of Propane is: 60 Molecular weight of Butanol is: 74 Molecular weight of Propanol is: 60 Molecular weight of Pentanol is: 88 The alcohol with the smallest molar mass is Methanol with a mass of: 32 The alcohol with the largest molar mass is Pentanol with a mass of: 88

(Submission instructions are on the next page)

Your electronic submission (submitted via Desire2Learn) will consist of three files:

1. A written report that begins with a title page that includes your name and student number. That should be followed by two sections, with each part clearly identified with a section heading. Include: • the code written in your MATLAB script • the output from running your program (copy and paste from Molecular_Weight.txt)

This written report should be prepared using a word processor. (Copy & paste your code from your MATLAB script and the command window into the report document and add appropriate headings.) The report document should then be stored as a SINGLE pdf file and submitted to the appropriate drop box on Desire2Learn. (This pdf will allow the marker to write comments directly on your work to give you better feedback.) Name this report as follows: YourName_As5_Report.pdf

2. Your output file Molecular_Weight.txt

3. Your MATLAB script (.m) that contains your code for the assignment with the name YourName_As5.m.

  • Assignment 5 CS1003