Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CSE1PES: PROGRAMMING FOR ENGINEERS AND SCIENTISTS ASSIGNMENT XXXXXXXXXX%) Assignment developed by Matthew Felicetti 2020 TOOLS • Unix server through Putty for compiling and testing • Notepad...

1 answer below »
CSE1PES: PROGRAMMING FOR ENGINEERS AND SCIENTISTS
ASSIGNMENT XXXXXXXXXX%)
Assignment developed by Matthew Felicetti 2020
TOOLS
• Unix server through Putty for compiling and testing
• Notepad XXXXXXXXXXfor writing solutions
• LMS for submission
SUBMISSION

The task requires ONE submission:
• The code for assignment 2
o Submitted as a .c file in the normal assignment submission portal.
o (Do not submit the executable.)
o There is NO late submissions for this assignment.
o Requests for extensions, need to be sent by email:
▪ Doctors certificates need to cover a period greater than 3 days, and not submitted less
than 3 days before the assignment is due.
▪ Special consideration will be rejected due to the assignment being worth less than
15%.
o Filenames must be in the format
_assign2.c
DUE DATE AND TIME
23RD of May 2020, 11PM
There is NO late submissions for this assignment. No assignment will be accepted after the due date,
without a legitimate extension granted by the subject coordinator before the due date.
ACADEMIC INTEGRITY
Plagiarism is the submission of somebody else’s work in a manner that gives the impression that the
work is your own. For individual assignments, plagiarism includes the case where two or more students
work collaboratively on the assignment. The School of Engineering and Mathematics treats plagiarism
very seriously. When it is detected, penalties are strictly imposed.
http:
www.latrobe.edu.au/students/academic-integrity
http:
www.latrobe.edu.au/students/academic-integrity
PRELIMINARY TASK – DOWNLOAD THE CODE PACKAGE
On Unix, create a directory named 'assignment_2' if you have not done so already (see lab0)
Change into this directory
Copy the files using the command below:
cp ~csili
cse1pes/students/assign2
student_numbe
* .
eplace with your student numbe
What is cp?
cp is the copy command in Unix
The first argument is the source and the second the destination
cp source destination
Why is the destination a .
If you put a . as the second argument, it will take the name of the file/s you are copying
Make sure you have your version.
Even though they look like others, they are NOT the same.
Every student’s template contains various unique signatures.
Using someone else's version or code from another version
will result in a mark of 0
BACKGROUND
BACKGROUND - TASK
You are tasked with writing one c program related to chemical compounds and elements. In the task, given
a set of compounds, two reactants and two products, and you will determine if the reactants and products
are balanced.
BACKGROUND – CHEMICAL ELEMENTS
A chemical element is a type of atom that makes up all the ordinary matter in the universe, and is defined
y the number of protons in its nucleus. Cu
ently there are 118 known elements.
These 118 can be represented on the periodic table of chemical elements as shown below:
BACKGROUND – ATOMIC NUMBERS AND ELEMENT SYMBOLS
The elements are all given names but are often represented as a series of letters (element symbol),
starting with an Upper-case letter and following with zero, one or two lower case letters. These can be
seen on the periodic table as shown below.
Periodic Table
Source: LeVanHan
Creative Commons
Element Name
Element Symbol
Beryllium
Source: LeVanHan
Creative Commons
BACKGROUND – CHEMICAL COMPOUNDS
A chemical compound or molecule is collection of atoms of more than one chemical element held together
y chemical bonds. A common example of this is pure water, which is made up of two Hydrogen atoms and
one Oxygen atom that are chemically bound.
BACKGROUND – CHEMICAL FORMULA (MOLECULAR FORMULA)
A chemical formula lists the elements and the proportion of atoms per element using element symbols.
More specifically the chemical formula written as a molecular formula includes the exact number of atoms
per element using element symbols. This is done by listing the symbols and a subscript to indicate the
number of atoms for a particular atom (with no subscript indicating one).
Example:
?2?
Looking at our periodic table we can see the symbol H stands for Hydrogen, and O for oxygen. The subscript
2, indicates that there are two Hydrogen atoms and one Oxygen atom.
BACKGROUND – CHEMICAL REACTION
A chemical reaction is a process where one or more compounds/elements known as the reactants
are converted into one or more different compounds/elements known as the products. The
eactants and products will have an equal amount of atoms of the same elements.
Example
When iron and sulphur combine they form iron sulphide
This can be represented using the following form (chemical equation)
?? + ? → ???
The compounds on the left-hand side of the a
ow are the reactants and the
products on the right. A + on the left-hand side can be thought of as “plus”, where as
a + on the right-hand side can be thought of as “and”.
For our program we will accept two reactants and two products.
Model of a Pure Water Molecule
Public Domain
BACKGROUND – BALANCED CHEMICAL EQUATION
Given the following chemical equation
?3?8 + ?2 → ?2? + ??2
On the left hand side we can see there are
3 ca
on (C) atoms
8 hydrogen (H) atoms
2 oxygen (O) atoms
On the right hand side we can see there are
1 ca
on (C) atom
2 hydrogen (H) atoms
3 Oxygen (O) atoms
As these are not equal the chemical equation is NOT balanced.
To balance these we apply coefficients to the compounds. These coefficients multiply the number of atoms in the
compounds.
Hence a balanced version of the above equation is
?3?8 + 5?2 → 4?2? + 3??2
On the left hand side we can see there are
3 ca
on (C) atoms
8 hydrogen (H) atoms
10 oxygen (O) atoms (5x2 =10)
On the right hand side we can see there are
3 ca
on (C) atom
8 hydrogen (H) atoms (4x2 = 8)
10 Oxygen (O) atoms (4x1 + 3x2 = 10)
BACKGROUND – INPUT
As we cannot use subscript, the number of atoms will be always to the right of the element
symbol.
Example:
4?2? will be written as 4H2O
2???4???2 will be written as 2BBe4CaH2
E
ors:
It is expected that all molecular formulas will be co
ectly formatted but may not be balanced.
BACKGROUND - LIMITATIONS AND NOTES
E
or checking – User input
The data entered by the user will be in the co
ect format of a chemical equation
Number of compounds – User input
Any of the products or reactants may be an empty String.
User input
The user input must accept any compound, i.e. do not hard code the compounds.
Compounds and Elements
An element will not appear twice in any single compound but may appear in both products and/or
oth reactants.
The number of atoms for each element in any single compound will be between 1 and 9, but the
total combined for the reactants and/or products may be higher
Elements will be limited to those with 1 or 2 character element symbols
CONSTRAINTS
• Formatting needs to be as specified. (Your program will be tested against automated test cases.)
• Text to user needs to be easily understandable.
• The program must print your student number as specified.
• Types should be used and named scientifically and appropriately.
• You must use comments to explain significant lines of code.
• The code must be done using ANSI C and compile on latcs5.cs.latrobe.edu.au using gcc.
• You must not use
eak, goto, or global variables in the assignment.
• You are only allowed to include the stdio.h, stdlib.h and string.h header file. No others. Do not
use conio.h.
• Checks must be commented out - NOT REMOVED - as they will be used in marking.
• Do not change function prototypes
TASK
STOP: READ THE BACKGROUND INFORMATION FIRST
PART 1
Given that the function numeric_char_to_decimal_int has been written for you.
Add a comment above the function (not the prototype) numeric_char_to_decimal_int
Explain the parameters and what is returned
Explain what the function is for basically
Explain how the function works using proper terminology covered in the subject
Given that the function get_coefficient has been written for you.
The purpose of this function is that, given a compound (see background), it will find the coefficient if there is one, "remove" it
from the string, and return the value, else it will return 1.
Add a comment above the function (not the prototype) get_coefficient
Explain the parameters and what is returned
Explain how the function checks if there is a coefficient
Explain how the function "removes" the coefficient (is it really removed?)
Explain why the double pointer is necessary (why would this not work with a single pointer?)
PART 2
Given the empty function and function prototype, get_compound
Complete this empty function so that it behaves as follows:
This function should ask the user for the compound, indicating the number n (see example below).
Then should store the string response from the user.
Once the function is written, check the code, using the checks provided in main.
An example is shown below:

Comment out the checks when done checking
PART 3
Given the empty function and function prototype, remove_chars_from_str
Complete this empty function so that it behaves as follows:
This function takes as input a number, num. It then moves the characters in the string “to the left” by that number of
characters, so as to shorten the string by num characters.
Write the code that moves characters in the string, as to shorten the string by num characters
Example:
Given the string:
'H' 'e' 'l' 'l' 'o' '\0' (null
terminator)
And we want to remove the first two characters, the string becomes
'l' 'l' 'o' '\0' (null
terminator)
'o' '\0' (null
terminator)

Notice that we don't move what is after the null terminator? You should understand why.
1. For loop that counts from 0, to the length of the string minus num (inclusive), incrementing by 1
2
Answered Same Day May 19, 2021 CSE1PES La Trobe University

Solution

Ria answered on May 22 2021
164 Votes
Screenshot from 2020-05-22 10-01-35.png
solution.c
#include                                                                                                                                                                                                                                                                 
:;
=:=<;;>::<:<=>=
;>=<==<=:>20103541
#include                                                                                                                                                                                                                                                                 
=
:=;<::
=<=:=:;==;<=<;>20103541
#include                                                                                                                                                                                                                                                                 
;
;;
=>==:
:=<=:<:;:=:>=>;
20103541
#define MAX_STR_LEN 128                                                                                                                                                                                                                                                            
=:=<;;:=;:=:=>:==;=;;<=
=:=;::>20103541
int numeric_char_to_decimal_int(char input);                                                                                                                                                                                                                                
==<;;=;;;;;=>;;=<:<=
=
;>:=20103541
void get_compound(char* compound, int n);                                                                                                                                                                                                                                    
:;
:==>;:
;=;>=;=;:<;;=<==>;:20103541
int get_coefficient(char** compound_ptr);                                                                                                                                                                                                                                    
:::<;:=:;:>:;<==:>;=;;;=>=;>:>::20103541
void remove_chars_from_str(char* str, int length);                                                                                                                                                                                                                        
:<:=<::=:>:;;;;>:=
;
:>:
;20103541
int balance_check(int* coefficients, char* reactants, char* products, int reactant_1_length, int product_1_length);                                                                                                                                
;
=
=>::
;>=
:=:;
;
==>:>20103541
int get_total_reactant_atoms_cu
ent_element(int* coefficients, int reactant_1_length, char* reactants, char* cu
ent_element, int number_of_atoms, int i);                                                                            
=;
=<;=:;<;:::;==;;::
=:;:
20103541
int get_total_product_atoms_cu
ent_element(int* coefficients, int product_1_length, char* products, char* cu
ent_element, int number_of_atoms);                                                                                        
;=>;==:=
;<:
::==:=
:<:=
;20103541
int main()
{
printf("** Student Number: 99999999 **\n");                                                                                                                                                                                                                            
:<;:=;:>=<=
=:<=:<;
=;
:
20103541
printf("Chemical Reaction Balance Check\n\n\n");                                                                                                                                                                                                                    
=<=:<;;
;;:=;=::<;<:=>:;=
=;20103541
char* reactant_1_orginal = (char*)malloc(sizeof(char)*MAX_STR_LEN);                                                                                                                                                                                            
:<:::==;;>:;>;
=;=;==:=::
::>20103541
char* reactant_2_orginal = (char*)malloc(sizeof(char)*MAX_STR_LEN);                                                                                                                                                                                            
=
:=<=
=<=;;::<:;:>=:;=<:<=<==20103541
char* product_1_orginal = (char*)malloc(sizeof(char)*MAX_STR_LEN);                                                                                                                                                                                            
:<:=:=>;<=>=:<=
;<:
;<:;;:
=;20103541
char* product_2_orginal = (char*)malloc(sizeof(char)*MAX_STR_LEN);                                                                                                                                                                                            
;:;==:>::;;<=
;>:<=;:===:
=:>20103541
get_compound(reactant_1_orginal, 1);                                                                                                                                                                                                                                    
:;
=>;::<=:
:;;
=>:=::
;>=;20103541
get_compound(reactant_2_orginal, 2);                                                                                                                                                                                                                                    
=<:
;:>:<:<:
=
=>;=
=;>20103541
get_compound(product_1_orginal, 3);                                                                                                                                                                                                                                    
==;
=;;
==:;;>:===<:<=;<==:
;20103541
get_compound(product_2_orginal, 4);                                                                                                                                                                                                                                    
:=<=<=>;=:;>;:>;=:=:>==;;==:
:20103541
printf("CHECK: reactant_1_orginal = %s\n", reactant_1_orginal);                                                                                                                                                                                                
:<=
=:;
=:====
::<;=::=>20103541
printf("CHECK: reactant_2_orginal = %s\n", reactant_2_orginal);                                                                                                                                                                                                
:;
=<;
;<=
;
==::;:::20103541
printf("CHECK: product_1_orginal = %s\n", product_1_orginal);                                                                                                                                                                                                    
;:<==;=
=:<:<;=;>;<;<:
:;20103541
printf("CHECK: product_2_orginal = %s\n", product_2_orginal);                                                                                                                                                                                                    
:<:;>:;<==<;
=
::=;=<:
==:>20103541
char* reactant_1_copy = reactant_1_orginal;                                                                                                                                                                                                                            
:<:
=>;==
:>;>;>;;::>:>;>=
20103541
char* reactant_2_copy = reactant_2_orginal;                                                                                                                                                                                                                            
;
:<:>=>;<===
;<;::=>;;=::
20103541
char* product_1_copy = product_1_orginal;                                                                                                                                                                                                                            
;;=<::==>;:
:;;;;
;:=<====;:>20103541
char* product_2_copy = product_2_orginal;                                                                                                                                                                                                                            
=<==>;=>::=
:==:
:<=;=;
=>:20103541
int coefficients[4];                                                                                                                                                                                                                                                        
;=>;=
;
=;;
;=:>=>:;<;<;
20103541
coefficients[0] = get_coefficient(&reactant_1_copy);                                                                                                                                                                                                                
;==;;>::;
===>;<:<:;>==;:;:>;=20103541
coefficients[1] = get_coefficient(&reactant_2_copy);                                                                                                                                                                                                                
=
;:>;;;=;>;;=>=:<:;;:
=:
=<20103541
coefficients[2] = get_coefficient(&product_1_copy);                                                                                                                                                                                                                
::=;
:;:
:
:;<:=<:;
=
:20103541
coefficients[3] = get_coefficient(&product_2_copy);                                                                                                                                                                                                                
=;====:<:>;
:;;=;====
:::;<:20103541
printf("CHECK: reactant_1_copy = %s\n", reactant_1_copy);                                                                                                                                                                                                        
:;=;;=;=<;:=;>;>:>::=:>:>;<:=;<:20103541
printf("CHECK: reactant_2_copy = %s\n", reactant_2_copy);                                                                                                                                                                                                        
=::
==>=>:>=<;;
;;;;=:==;<:;20103541
printf("CHECK: product_1_copy = %s\n", product_1_copy);                                                                                                                                                                                                            
;;;:
:==;:
:=
:
:
:;>;<:20103541
printf("CHECK: product_2_copy = %s\n", product_2_copy);                                                                                                                                                                                                            
:<;:=<:;==;
;:>=::
:
;:=
;=20103541
int...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here