Docsity

computer engineering, Schemes and Mind Maps of Computer Engineering and Programming

Toggle sidebar
bg1
QUESTION 1
(1.1)
#include <stdio.h>
int main() {
int temperature;
printf("Enter temperature (°C):");
scanf("%d", &temperature);
//out of range(invalid range)
if(temperature<-50 &&temperature<100){
printf("Error message");
}
//heating element activation
else if(temperature <10){
printf("activates heating element");
}
//normal operation
else if(temperature>=10 && temperature <=30){
printf("maintain normal operation") ;
}
//cooling fan
else if(temperature>=31 && temperature<=50)
printf("activate the cooling fan");
}
//overheat alarm
else{
printf("overheat alarm");
}
return 0;
}
pseudocode
START
INPUT TEMPERATURE
If temperature <-50 &&temperature<100 then
print("Error message:out of range")
If temperature <10 then
print("heating element activation")
If temperature>=10 \&\& temperature <=30 then
print("normal operation")
If temperature >=31 \&\& temperature<=50 then
print("cooling fan is activated")
pf3
pf4
pf5

Partial preview of the text

Download computer engineering and more Schemes and Mind Maps Computer Engineering and Programming in PDF only on Docsity!

QUESTION 1

#include int main() { int temperature; printf("Enter temperature (°C):"); scanf("%d", &temperature); //out of range(invalid range) if(temperature<-50 &&temperature<100){ printf("Error message"); } //heating element activation else if(temperature <10){ printf("activates heating element"); } //normal operation else if(temperature>=10 && temperature <=30){ printf("maintain normal operation") ; } //cooling fan else if(temperature>=31 && temperature<=50) printf("activate the cooling fan"); } //overheat alarm else{ printf("overheat alarm"); } return 0; } pseudocode START INPUT TEMPERATURE If temperature <-50 &&temperature<100 then print("Error message:out of range") If temperature <10 then print("heating element activation") If temperature>=10 &amp;&amp; temperature <=30 then print("normal operation") If temperature >=31 &amp;&amp; temperature<=50 then print("cooling fan is activated")

ELSE

print ("over heat alarm triggered ") END (1.2) #include int main() { int temperature; //temperature input printf("Enter temperature (°C):"); scanf("%d", &temperature); //validate temperature range if(temperature<-50 || temperature<100){ printf("Error message"); } //heating element activation else if(temperature <10){ printf("activates heating element"); } //normal operation else if(temperature>=10 && temperature <=30){ printf("maintain nornal operation") ; } //cooling fan else if(temperature >=31 && temperature<=50){ printf("activate the cooling fan"); } //overheat alarm else{ printf("overheat alarm"); } return 0; } (1.3) START Input temperature Input temperature // Validate temperature1 and temperature IF (temperature1 < -50 OR temperature1 > 100) OR (temperature2 < -50 OR temperature2 > 100) then

// Input temperatures printf("Enter temperature for Zone 1: "); scanf("%f", &temperature1); printf("Enter temperature for Zone 2: "); scanf("%f", &temperature2); // Validate temperature1 amd temperature if ((temperature1 < -50 || temperature1 > 100) || (temperature2 < -50 || temperature2 > 100)) { printf("Error: One or both temperatures out of valid range\n"); } // If temperature1 equals temperature 2 else if (temperature1 == temperature2) { if (temperature1 < 10) { printf("Heating element activated (Both Zones)\n"); } else if (temperature1 <= 30) { printf("System in normal operation (Both Zones)\n"); } else if (temperature1 <= 50) { printf("Cooling fan is activated (Both Zones)\n"); } else { printf("over heat alarm id triggered (Both Zones)\n"); } } // If temperatures are different else { // Zone 1 if (temperature1 < 10) { printf("Zone 1: Heating element activated#include int main() { int temperature1 , temperature2; // Input temperatures printf("Enter temperature for Zone 1: "); scanf("%f", &temperature1); printf("Enter temperature for Zone 2: "); scanf("%f", &temperature2); // Validate temperature1 amd temperature if ((temperature1 < -50 || temperature1 > 100) || (temperature2 < -50 ||

temperature2 > 100)) { printf("Error: One or both temperatures out of valid range\n"); } // If temperature1 equals temperature 2 else if (temperature1 == temperature2) { if (temperature1 < 10) { printf("Heating element activated (Both Zones)\n"); } else if (temperature1 <= 30) { printf("System in normal operation (Both Zones)\n"); } else if (temperature1 <= 50) { printf("Cooling fan is activated (Both Zones)\n"); } else { printf("over heat alarm id triggered (Both Zones)\n"); } } // If temperatures are different else { // Zone 1 if (temperature1 < 10) { printf("Zone 1: Heating element activated\n"); } else if (temperature1 <= 30) { printf("Zone 1: NORMAL operation\n"); } else if (temperature1 <= 50) { printf("Zone 1: Cooling fan activated\n"); } else { printf("Zone 1: overheat alarm triggered\n"); } // Zone 2 if (temperature2 < 10) { printf("Zone 2: Heating element activated\n"); } else if (temperature2 <= 30) { printf("Zone 2: NORMAL operation\n"); } else if (temperature2 <= 50) { printf("Zone 2: Cooling fan activated\n"); } else { printf("Zone 2: overheat alarm triggered\n");