In: Computer Science
You are to create a program to request user input and store the data in an array of structures, and then display the data as requested. The data you are collecting refers to a set of images. The images are OCT images taken of the lining of the bladder. The data you provide will help diagnose the image as cancerous or not, but your code does not need to do that at the moment.
First, Define a global structure that contains the following information:
a) File number (must be >0)
b) Diagnosis number (1-8)
c) Number of layers in the image
d) Maximum average intensity of a single row (should be a float) e)
Width of brightest layer
Next, Declare an array of the 9 of structures in the first part. This array should be be a global variable.
Next, Initialize each of the file numbers in the array to -1.
After, Create a loop that will continue asking the user for the above data until the file number 0 is given, or until information has been provided for 9 images.
Next, If the user provides a file number less than 0, ask again. Do not ask for further information if the user provides a file number equal to 0.
Then, If the user provides a diagnosis number that is not between 1 and 8, ask again.
Next, Store the data in the array of structures in the order it is provided.
Now, Write a function to display the information for a particular file number. If the file number was not found, nothing is displayed. The function will return a 1 if the file number was found or a 0 if the file number was not in the array.
Next, In your main function, after the loop which requests the data, create another loop that will request a file number from the user and then call the function written for #8 to display the data for that file number. This loop will continue until a file number is provided that is not found.
Finally, In your main function, after the code for #9, add a loop that will display the information for all items stored in the array in order.
C++ Coding Please
SOLUTION:
Code for given problem statement:
#include<stdio.h>
struct OCT // Global structure for storing OCT information
{
int file_number,Diagnosis_number,nlayers;
float average_intensity,width;
};
struct OCT obj[9]; // Global array of structure
int find_file(int input,int sizes) // Function to provide details
for given file number
{
for(int i=0;i<sizes;i++)
{
if(input==obj[i].file_number)
{
// Print details if found and returns 1
printf("The details for the given file number are:\n");
printf("File Number: %d\n",obj[i].file_number);
printf("Diagnosis Number: %d\n",obj[i].Diagnosis_number);
printf("Number of layers in the image: %d\n",obj[i].nlayers);
printf("Maximum average intensity of a single row:
%f\n",obj[i].average_intensity);
printf("Width of brightest layer: %f\n",obj[i].width);
return 1;
}
}
printf("Given file number not found\n");
return 0; // If file number not found return 0
}
int main()
{
for(int i=0;i<9;i++)
{
obj[i].file_number=-1; // Initializing all file numbers to -1
}
int n=0;
while(n<9) // Loop for taking information from user for upto 9
OCTs
{
printf("Enter details for OCT number: %d\n",n+1);
printf("Enter File Number: ");
scanf("%d",&obj[n].file_number);
while(obj[n].file_number<0) // Loop untill file number is
>=0
{
printf("The file number should be greater than 0: ");
scanf("%d",&obj[n].file_number);
}
if(obj[n].file_number==0) // User wants to exit
{
break;
}
printf("Enter Diagnosis Number: ");
scanf("%d",&obj[n].Diagnosis_number);
while(obj[n].Diagnosis_number>8 || obj[n].Diagnosis_number<1)
// loop untill diagnosis number is between 1-8
{
printf("Diagnosis number should be between 1 and 8: ");
scanf("%d",&obj[n].Diagnosis_number);
}
printf("Enter Number of layers in the image: ");
scanf("%d",&obj[n].nlayers);
printf("Enter Maximum average intensity of a single row: ");
scanf("%f",&obj[n].average_intensity);
printf("Width of brightest layer: ");
scanf("%f",&obj[n].width);
printf("Details Recorded\n\n");
n++;
}
int total_size=n;
int input;
printf("\n");
printf("Enter file number whose all details are required: ");
scanf("%d",&input);
while(find_file(input,total_size)) // For finding details for given
file untill given file number is not found
{
printf("\nEnter next file number for details: ");
scanf("%d",&input);
printf("\n");
}
printf("\n");
printf("Details for all the OCTs\n");
printf("\n");
for(int i=0;i<total_size;i++) // Prints details for all
available OCTs
{
printf("#%d:\n",i+1);
printf("File Number: %d\n",obj[i].file_number);
printf("Diagnosis Number: %d\n",obj[i].Diagnosis_number);
printf("Number of layers in the image: %d\n",obj[i].nlayers);
printf("Maximum average intensity of a single row:
%f\n",obj[i].average_intensity);
printf("Width of brightest layer: %f\n",obj[i].width);
printf("\n");
}
return 0;
}
Screenshot of code:
Screenshot of output:
Both images are of a single output
Logic of the code:
Initially structure and array of structure of size 9 is declared globally.
The structure has following data members:
a) File number is stored as int
b) Diagnosis number is stored as in
c) Number of layers in the image is stored as int
d) Maximum average intensity of a single row is stored as float
e) Width of brightest layer is stored as float
In main function the information is taken from the user.
The conditions for file number and diagnosis number are applied in the code as per given in the problem statement.
Next part of the code is searching and printing details for the given file number by user. A function is used for this which return 1 if record is found and prints it. If record is not found then 0 is returned.
The loop runs untill user gives file number which doen't exist in given data base.
At the end All the available information for all the OSTs is printed.