Assignment

hey i have been given the following assignment, but i cant understand it. Can anybody elaborate it. Thanks.

A cup of water (250 ml) is heated from 0 to 100 C. Find the change in internal energy (Required heat to boil) for the cup of water, and keep printing it for temperatures in range 5 - 100 C. Change temperature using function call by reference. Make functions for calculating mass() and req_heat() as well. Density = 1, w_cp = 4.2.
Formulas
*mass = density * volume
req_heat = w_cp * mass * (max_temp - altered_temp)
use const for universal constants.
closed account (zb0S216C)
All you need is right there. Have you even attempted to write the code?
yup the code is here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<conio.h>
#include<windows.h>

using namespace std;
void mass(double&);
void req_heat(int&,int& );

double m=0;
int main()
{
    int alt_temp=5,r_heat=0,i;
    mass(m);  
    for (i=0;i<100;i++)
    {
        req_heat(r_heat,alt_temp);
        cout<<r_heat<<"::"<<alt_temp<<endl;
        alt_temp++;
        Sleep(300);
        
    }
        
    getch();
    return 0;
}

void mass(double &m1)
{
    m1=1*0.250;
}

void req_heat(int &rheat,int &alttemp)
{
    int max_temp=100;
     rheat=4.2*m*(max_temp-alttemp);
}


but i dnt think i am doing it right way...
what to do?
The code looks ok by just scanning it over. Did it compile? If so, put in some dummy numbers and calculate it by hand. If your hand calculation is the same as the output, you know it works. If it didn't compile, look at the output and fix the stated errors. Then recompile and test again.
When I compiled, in line 35 (function 'void req_heat(int&, int&)':
[Warning] converting to int from double.

I changed int &alttemp to a double value. It works now.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include<conio.h>
#include<windows.h>

using namespace std;
void mass(double&);
void req_heat(int&,int& );

double m=0;
int main()
{
    int alt_temp=5,r_heat=0,i;
    mass(m);
    for (i=0;i<100;i++)
    {
        req_heat(r_heat,alt_temp);
        cout<<r_heat<<"::"<<alt_temp<<endl;
        alt_temp++;
        Sleep(300);

    }

    getch();
    return 0;
}

void mass(double &m1)
{
    m1=1*0.250;
}

void req_heat(int &rheat,double &alttemp)
{
    int max_temp=100;
     rheat=4.2*m*(max_temp-alttemp);  // double*int is not valid
}
Last edited on
Topic archived. No new replies allowed.