Sunteți pe pagina 1din 9

GNG1106 Fall 2019 - Assignment 3

Due: October 11, 11:30PM

Instructions
This assignment is to be done INDIVIDUALLY. Follow the instructions in the GNGBlackboard document that describes
how to submit assignments through the Blackboard. The following are specific instructions for this assignment:

• You will need to submit your assignment electronically to Blackboard. Submit the following
o An assignment report in a PDF file (this allows you to use your favorite editor to create the PDF file). For question
1, insert the programming models for parts (a) and (b) filled in as per the question instructions. You may fill in the
programming model using drawing features of your editor or by hand on paper which is then scanned and inserted
into your document. For Question 2, insert in your assignment report the source code (take care in its appearance),
and capture the output from running the program for all test cases. Also submit your source code files for question
2.
• Place all your files (PDF file and C source code files) in a zip file with the name A2_xxxxxx.zip where xxxxxx is your
student number and submit the zip file before the assignment deadline.
• The questions are provided in both PDF and Word files. You may use the Word file to enter your answers in the
document.
• It is NOT permitted to use instructions that have not yet been covered in the lectures.

Marking Scheme (total 30 marks)


• Question 1: 15 marks
• Question 2: 15 marks
Question 1 (15 marks)

(a) (10 points) The following programming model contains in its program memory the indicated C program composed of 2
functions. You will be showing how the working memory is used during the execution of the two functions. Each piece
of working memory is associated to a function using a pair of lines. (Note: the first pair of lines associates the piece of
working memory allocated to the function main and the second pair of lines associates the piece allocated to the
function computeNetResistance). Show how the given C program affects the contents of the working memory:
• Show how the structure is organized in the working memory for each function.
• Show the values are assigned to the members of the structure. Be sure to show all values that are assigned and
replaced. Record successive assignments to variables/parameters as follows:

Variable ? 2, 6, 4, 10
name
• Using arrows show how values are copied between the working memory allocated to the function main and the
working memory allocated to the function computeNetResistance. For copying the contents of a structure
variable, you need only used a single arrow.
• In the console window show the output of the program.

type = ? p
resistor1= ? 1.5
resistor2= ? 3.2
resistor3= ? 4.7
netResistance = ? 0.84

netResistance = ? 1.19
0.84

The circuit has a type of p


The three resistor values are 1.50,
3.20, 4.70
The net resistance of the circuit is 0.84

Note: You do NOT need to show how the CPU interacts with memory.
(b) (5 marks) The following programming model contains in its program memory the indicated C program composed of a
single main function. You will be showing how the working memory is used during the execution of main. Show how
the given C program affects the contents of the working memory:
• Show the values are assigned to the variables. Be sure to show all values that are assigned and replaced. Record
successive assignments to variables/parameters as follows:

Variable ? 2, 6, 4, 10
name

x = ? 8.9
realArray[0] = ? 2.1
realArray[1] = ? 3.2
realArray[2] = ? 4.7
realArray[3] = ? 5.2
realArray[5] = ? 7.3
realArray[6] = ? 0
realArray[7] = ? 0
realArray[8] = ? 12.3
realArray[9] = ? 8.9
Question 2 (15 marks)

Consider the problem of computing the rise in temperature in a room with a number of students.
Each students takes up about 0.075 m3 (which reduces the air volume in the room) and will give
out heat at a rate of 80 W (1 W = 1 J/s) which will increase the air temperature in the room.
The amount of heat, Q (kJ), absorbed by the air is related to the volume of air, the heat capacity of
air, and the change in temperature (degrees K) according to the following equation.
Q = mCv (T2 − T1 )
The heat capacity, Cv, for air can be assumed to be 0.718 kJ/(kg K). Thus temperature is in Kelvin
in the above equation. The ideal gas law (recall assignment 1) can be used to obtain the mass of the
air.
m
PV = RT
M
where P is the gas pressure in units of kPa (kilo pascals),
V is the gas volume in cubic meters (m3),
T is the temperature in degrees Kelvin,
M is the molecular weight of the gas in kg/kmole (for air, M = 28.97 kg/kmole),
m is the weight of the gas in kg,
R is the idle gas constant with the value 8.314 kPa m3/(kmole K).
You may assume an initial pressure of 1 atm (101.325 kPascals).
Develop a computer program that computes the rise in the temperature in the room after a given
time t. Follow the following guidelines:
• In your program, use a C structure
o With members that define the dimension of the room (height, width and length), the number of
students in the room, the initial temperature in the room and the time for computing the rise in
temperature.
• Requests from the user the following information:
o Number of students in the room,
o The initial temperature in the room (degrees Celsius),
o Three dimensions of the room (height, length, width in meters),
o A time in minutes for calculating the increase in temperature of the room. This is the time that
students are in the classroom.
o All input data shall be stored in a structure variable.
• Use symbolic constants to define: heat capacity of air, molecular weight of the air, ideal gas constant, the
rate at which heat is given off by students, the volume occupied by a student, and the room pressure at
the initial temperature.
• Use a separate function (other than main) to compute the rise in temperature. Use appropriate
parameters and return the final temperature in the room.
• The main function gets input values from the user, calls the function to compute the rise in temperature
and displays results to the user. Use an appropriate output message to display values provided by the
user and the final temperature. Use output formatting to display 2 decimal values.
The following table provides test cases that can be used for testing the software.

Room Dimensions Initial Final


Number (meters) Time
Temperature Temperature
Students (min)
(Celsius) (Celsius)
Height Width Length
20 3.00 10.00 30.00 20.00 15.00 21.85
35 3.00 10.00 30.00 20.00 15.00 23.25
50 3.00 10.00 30.00 20.00 15.00 24.64
35 2.25 5.55 12.15 15.50 30.00 53.99
10 3.50 15.50 21.40 25.00 15.00 25.73
2 2.50 4.10 5.60 20.00 15.00 22.91
0 2.50 4.10 5.60 20.00 15.00 20.00

The answer to this question should provide:


1) The source code to your program.
#include <stdio.h>
#include <math.h>
#define R 8.3145
#define MWair 28.97
#define rHeat 0.08
#define Vstudent 0.075
#define P 101.325
#define Cv 0.718

double m (double, double, double, double);


double TempC(double, double, double, double, double);

typedef struct
{
double l;
double w;
double h;

}DIMENSON;

double main()

{
DIMENSON dim1;
double numStudents, Tinital, Timeinclass, mass,Tfinal, D;
printf("How many students are in the room?\n");
scanf("%lf", &numStudents);

printf("What is the inital temperature of the room?\n");


scanf("%lf", &Tinital);

printf("For how long are they in the class for?\n");


scanf("%lf", &Timeinclass);

printf("Enter the dimensons of the class room (length, width, height).\n");


scanf("%lf %lf %lf", &dim1.l, &dim1.w, &dim1.h);

D = dim1.l*dim1.w*dim1.h;
Tinital = 273.15+Tinital;

mass = m(numStudents, mass, Tinital, D);


Tfinal = TempC(Tfinal, mass, Tinital, Timeinclass, numStudents);
printf("The final tempurature in the room after %.2lf minutes with %.2lf students in it is %.2lf celsius",
Timeinclass, numStudents, Tfinal);
}

double m(double mass , double numStudents, double Tinital, double D)


{
numStudents =D-numStudents*0.075;
mass = (P* numStudents);
mass = mass /(R*Tinital);
mass = mass*MWair;
return (mass);
}
double TempC(double Tfinal, double mass, double Tinital, double Timeinclass, double numStudents)
{
double Q;
Timeinclass = Timeinclass*60;
Q = 0.080*numStudents*Timeinclass;
Tfinal= Q/(mass*Cv);
Tfinal = Tfinal + Tinital;
Tfinal = Tfinal -273.15;
return (Tfinal);
}
2) Insert the output for each test case in the above table

S-ar putea să vă placă și