Create a C (NOT C++)! program (//please comment through code for clarification)
ID: 3804588 • Letter: C
Question
Create a C (NOT C++)! program (//please comment through code for clarification)
(MUST! have concepts of structures, arrays, enumerations, and unions. must have at least one array that stores all the packets received. but cannot have 2 arrays seperating satellite health information and experiment information)!
Description Create a C program that reads simulated satellite telemetry from standard input, performs a bit of analysis on that data and outputs a summary of the telemetry. This program is based on a real satellite.
Imagine there is a satellite, called Varmit-1, which sends telemetry to the ground. It must process two types of information, satellite health information and experiment information.
The satellite health information consists of two pieces of information:
float temperature;
float voltage;
You should represent the satellite health information as a structure with these two members.
The experiment information also consists of two pieces of information:
unsigned int radiation_count;
unsigned int latchup_events;
You should represent the satellite health information as a structure with these two members.
Because the satellite transmits only one type of packet at a time, either a packet of satellite health information or a packet of experiment information AND because memory is tight on the satellite, you should use a union to hold either satellite health information or experiment information in the minimum amount of memory.
Operation When the program starts, ask the user if they wish to:
1 – Enter a packet of satellite health information
2 – Enter a packet of experiment information
3 – Print summary information on the telemetry and exit the program
If the user wishes to enter a packet of satellite health information, you should prompt for the temperature and voltage and store that information for later processing.
If the user wishes to enter a packet of experiment information, you should prompt for the radiation_count and latchup_events and store that information for later processing.
If the user elects to print summary information and exit the program, you should process the data in the array and output:
• The number of satellite health information packets.
• The maximum temperature across all the satellite health information packets
.• The minimum temperature across all the satellite health information packets.
• The maximum voltage across all the satellite health information packets.
• The minimum voltage across all the satellite health information packets.
• The number of experiment information packets.
• The total sum of radiation_count across all the experiment information packets.
• The total sum of latchup_events across all the experiment information packets.
Ensure your program is well documented, well structured, and uses meaningful variable names. Use multiple functions as necessary for good structure and readability.
Sample Input and Output
Please enter the number for the desired action (1, 2, 3):
1 - Enter a packet of satellite health information
2 - Enter a packet of experiment information
3 - Print summary information on the telemetry and exit the program
1
Enter the temperature: 35.2
Enter the voltage: 12.4
Please enter the number for the desired action (1, 2, 3):
1 - Enter a packet of satellite health information
2 - Enter a packet of experiment information
3 - Print summary information on the telemetry and exit the program
2
Enter the radiation count: 121
Enter the latchup events: 2
Please enter the number for the desired action (1, 2, 3):
1 - Enter a packet of satellite health information
2 - Enter a packet of experiment information
3 - Print summary information on the telemetry and exit the program
1
Enter the temperature: 37.4
Enter the voltage: 12.1
Please enter the number for the desired action (1, 2, 3):
1 - Enter a packet of satellite health information
2 - Enter a packet of experiment information
3 - Print summary information on the telemetry and exit the program
2
Enter the radiation count: 56
Enter the latchup events: 3
Please enter the number for the desired action (1, 2, 3):
1 - Enter a packet of satellite health information
2 - Enter a packet of experiment information
3 - Print summary information on the telemetry and exit the program
3
Number of satellite health information packets: 2
Maximum temperature: 37.4
Minimum temperature: 35.2
Maximum voltage: 12.4
Minimum voltage: 12.1
Number of experiment information packets 2
Total radiation count: 177
Total latchup events: 5
Explanation / Answer
#include <stdio.h>
#include <limits.h>
#define n 100
void printMenu();
void printAllInfo();
void getSatHealthInfoPacket();
void getExperimentInfoPacket();
struct health_packet {
float voltage;
float temperature;
};
struct experiment_packet {
unsigned int radiation_count;
unsigned int latchup_events;
};
struct packet {
int packet_type;
struct health_packet health;
struct experiment_packet experiment;
};
struct packet data[n];
int count = 0;
void main() {
while (1) {
printMenu();
int choice;
scanf("%d", &choice);
switch(choice) {
case 1 :
getSatHealthInfoPacket(count++);
break;
case 2 :
getExperimentInfoPacket(count++);
break;
case 3 :
printAllInfo();
return;
default :
printf("Invalid Choice!! ");
}
}
}
void getSatHealthInfoPacket(int i) {
float temperature, voltage;
printf("Enter the temperature :");
scanf("%f", &temperature);
printf("Enter the voltage :");
scanf("%f", &voltage);
data[i].health.temperature = temperature;
data[i].health.voltage = voltage;
data[i].packet_type = 1;
printf("%d %d %f %f ",i,data[i].packet_type, data[i].health.temperature, data[i].health.voltage);
}
void getExperimentInfoPacket(int i) {
unsigned int radiation_count;
unsigned int latchup_events;
printf("Enter radion count : ");
scanf("%u", &radiation_count);
printf("Enter latch_up events :");
scanf("%u", &latchup_events);
data[i].experiment.latchup_events = latchup_events;
data[i].experiment.radiation_count = radiation_count;
data[i].packet_type = 2;
printf("%d %d %d %d ",i,data[i].packet_type, data[i].experiment.radiation_count, data[i].experiment.latchup_events);
}
void printAllInfo() {
float min_temp =INT_MAX, max_temp =INT_MIN, min_volt = INT_MAX, max_volt = INT_MIN;
int i, health_packet_count = 0, exp_packet_count = 0;
int total_radiation_count = 0, total_latch_count = 0;
for (i=0; i<count; i++) {
if (data[i].packet_type == 1) {
health_packet_count++;
if (min_temp > data[i].health.temperature) {
min_temp = data[i].health.temperature;
}
if (max_temp < data[i].health.temperature) {
max_temp = data[i].health.temperature;
}
if (min_volt > data[i].health.voltage) {
min_volt = data[i].health.voltage;
}
if (max_volt < data[i].health.voltage) {
max_volt = data[i].health.voltage;
}
}
else {
exp_packet_count++;
total_radiation_count += data[i].experiment.radiation_count;
total_latch_count += data[i].experiment.latchup_events;
}
}
printf("Number of satellite health information packets : %d ",health_packet_count);
printf("Maximum temperature : %f ", max_temp);
printf("Minimum temperature : %f ", min_temp);
printf("Maximum voltage : %f ", max_volt);
printf("Minimum voltage : %f ", min_volt);
printf("Number of experiment information packets : %d ", exp_packet_count);
printf("Total Radiation Count : %d ", total_radiation_count);
printf("Total Latch Count : %d ", total_latch_count);
}
void printMenu() {
printf(" Menu ");
printf("1. Enter a packet of satellite health information ");
printf("2. Enter a packet of experiment information ");
printf("3. Print summary and exit the program ");
printf("Enter your choice : ");
}