0% found this document useful (0 votes)
57 views7 pages

GNG1106 Winter 2016 - Assignment 3 Solution: Question 1 (15 Marks)

The document provides the solution to an assignment question involving calculating the increase in temperature of a room over time. It includes: 1) The C code for the solution with functions to get user input, calculate the final temperature, and display results. 2) A marking scheme that awards points for various aspects of the code like defining constants, structures, functions, calculations, and output. 3) The total marks awarded is 15 points.

Uploaded by

Chiheb Dz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views7 pages

GNG1106 Winter 2016 - Assignment 3 Solution: Question 1 (15 Marks)

The document provides the solution to an assignment question involving calculating the increase in temperature of a room over time. It includes: 1) The C code for the solution with functions to get user input, calculate the final temperature, and display results. 2) A marking scheme that awards points for various aspects of the code like defining constants, structures, functions, calculations, and output. 3) The total marks awarded is 15 points.

Uploaded by

Chiheb Dz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

GNG1106 Winter 2016 - Assignment 3 Solution

Deduct 0 to 5 points for not submitting assignment according to instructions (in a zip file,
directory, with source code, etc.)
Question 1 (15 marks)
(a) (10 marks)

Marking Scheme:
Variables in working memory for main 2.5 marks
1 for structure variable
1.5 for values (0.25 for each correct value and ? in netResistance.)
-0.5 for adding ? in members initialised
Variables in working memory for function computeNetResistance 3.5 marks
1 for parameter
1 for parameter structure member values
1.5 for values of netResistance variable (0.5 for ? and 0.5 for updated values)
-0.5 for adding value in netResistance member of parameter other than ?
-0.5 for adding ? in members other than netResistance
Exchange of values between working memory 2 marks
1 for each arrow
-0.5 if multiple arrows shown for updating values of the parameter
Console Output
1/3 mark for each output message 2 marks
-0.5 if formatting of values are not correct (only 2 decimal places in fraction)
Total 10 marks
(b) (5 marks)

Marking Scheme:
Defining the structure array in memory 1 marks
-0.5 if 10 elements are not present (ex. only 5 elements)
Array initialization 1 mark
0.5 for first five elements (0.1/value), 0.5 for zeros in last element
Defining variable x in memory with values 1 mark
0.5 for variable, 0.25 for ? and 0.25 for 8.9 value
Results for each operation 2 marks
(1 for each update to elements in the array)
Total 5 marks
Question 2 (10 marks)

/*--------------------------------------------
File: A2_Q3.c
Author: Gilbert Arbez, Fall 2016.
Computes the increase in temperature in a
room with students.
--------------------------------------------*/
#include <stdio.h>

//Symbolic constants
#define CV 718.0 // J/(kg K) - heat capacity
#define M 28.97 // kg/kmole - molecular weight
#define R 8.314 // kPa m^3/(kmole K) - idle gas constant
#define P 101.325 // kPascals - 1 atm pressure
#define T_CONV 273.15 // Conversion Kelvin/Celsius
#define V_STUDENT 0.075 // Volume of each student
#define H_STUDENT 80.0 // Heat from students (J/s)
#define NUM_SECONDS 60.0 // number of seconds in a minute
// Structure for dimension of room and number of students
typedef struct
{
int numStudents;
double height;
double width;
double length;
double temp_init;
double time;
} ROOM;
// Prototype
double computeFinalTemp(ROOM);
/*-----------------------------------------
Function: main
Description: Gets input from the user, calls
computeTempRise to compute the
rise in temperature and displays
results to user.
-------------------------------------------*/
void main()
{
ROOM theRoom;
double final_temp;
// Get values from the user
printf("How many students in the room: ");
scanf("%d", &theRoom.numStudents);
printf("Please provide height, width, and length of the room (in meters).\n");
scanf("%lf%lf%lf", &theRoom.height, &theRoom.length, &theRoom.width);
printf("What is the initial temperature (Celsius): ");
scanf("%lf", &theRoom.temp_init);
printf("At what time do you want to know the temperature: ");
scanf("%lf", &theRoom.time);
//Calculations
final_temp = computeFinalTemp(theRoom);
// Output the results
printf("For a room with dimensions %.2f X %.2f X %.2f\n",
theRoom.height, theRoom.width, theRoom.length);
printf("starting at temperature %.2f with %d students\n",
theRoom.temp_init, theRoom.numStudents);
printf("the temperature after %.2f minutes will be %.2f degrees Celsius\n",
theRoom.time, final_temp);
}
/*-------------------------------------------------------------
Function: computeFinalTemp
Parameters:
room - contains values provided by the user
Returns: The final temperature in the room after time room.time.
Description: Uses the information in the structures to compute
the final temperature in the room after room.time.
---------------------------------------------------------------*/
double computeFinalTemp(ROOM room)
{
//Declaration of variables
double tempK;
double volume;
double mass;
double temp_final;
double q;

tempK = room.temp_init + T_CONV;


volume = (room.height*room.length*room.width) - (room.numStudents*V_STUDENT);
mass = P*volume*M/(R*tempK);
q = room.numStudents*H_STUDENT*room.time*NUM_SECONDS; // Gives Joules of heat
temp_final = tempK + q/(mass*CV);
temp_final = temp_final - T_CONV;
return(temp_final);
}
Output
Marking Scheme:

C Program
Symbolic Constants 1.75 marks
0.25 mark each for required for total of 1.5
(Required: CV, M, R, P, V_STUDENT, H_STUDENT)
0.25 total for additional constants, i.e. do not use magic numbers
Structure definition 2 marks
0.25 for each member declaration (total 1.5)
0.5 for typedef struct { } ROOM; (type name does not need to be ROOM)
Main function (4.5 total marks))
Comments (header) 0.5 mark
Variable Declarations 1 mark
Input from user 1 mark
Calls to computeFinalTemp 1 mark
Display results 1 mark
Function angle (5 marks total)
Comments (header) 0.5 mark
Function header/prototype 1 mark
Variable declarations 1 mark
Calculations (1 mark for correctness, 1 mark for clarity) 2 marks
Return instruction 0.5 mark
Output (0.25 per output) 1.75 marks

Total 15 marks

You might also like