Question #7242

how would you write a program which uses a 1D array to store 10 temperature readings
and that the program include 4 functions main(),controller,ctof() and ftoc().
that the program is for converting fahrenheit to celcius
with it being Fahrenheit->Celcius /5*9 +32
Celius -> (Fahrenheit-32)/9*5

Expert's answer

#include <iostream>

using namespace std;

float * ctof(float

* deg){

float * res = new float[10];

for( int i=0; i<n; i++

){

res[i] = deg[i] * 9 / 5 + 32;

}

return res;

}

float *

ftoc(float * deg){

float * res = new float[10];

for( int i=0; i<n; i++

){

res[i] = (deg[i]-32) * 5 / 9;

}

return res;

}

void

controller(){

float * temp = new float [n];

cout<<"Input 10 value of

tempetarute in Fahrenheit\n";

for( int i=0; i<n; i++

){

cout<<i+1<<": ";

cin>>temp[i];

}

float *

cel = ftoc(temp);

cout<<"Celcius: "<<endl;

for( int i=0;

i<n; i++ ){

cout<<i+1<<":

"<<cel[i]<<endl;

}

float * fahr =

ctof(cel);

cout<<"Fahrenheit: "<<endl;

for( int i=0; i<n;

i++ ){

cout<<i+1<<":

"<<fahr[i]<<endl;

}

}

int

main(){

controller();

system("pause");

return 0;

}

using namespace std;

float * ctof(float

* deg){

float * res = new float[10];

for( int i=0; i<n; i++

){

res[i] = deg[i] * 9 / 5 + 32;

}

return res;

}

float *

ftoc(float * deg){

float * res = new float[10];

for( int i=0; i<n; i++

){

res[i] = (deg[i]-32) * 5 / 9;

}

return res;

}

void

controller(){

float * temp = new float [n];

cout<<"Input 10 value of

tempetarute in Fahrenheit\n";

for( int i=0; i<n; i++

){

cout<<i+1<<": ";

cin>>temp[i];

}

float *

cel = ftoc(temp);

cout<<"Celcius: "<<endl;

for( int i=0;

i<n; i++ ){

cout<<i+1<<":

"<<cel[i]<<endl;

}

float * fahr =

ctof(cel);

cout<<"Fahrenheit: "<<endl;

for( int i=0; i<n;

i++ ){

cout<<i+1<<":

"<<fahr[i]<<endl;

}

}

int

main(){

controller();

system("pause");

return 0;

}

## Comments

## Leave a comment