Question

In: Computer Science

You are to create a program to request user input and store the data in an...

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

Solutions

Expert Solution

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.


Related Solutions

This program must be in java, use printf, and request user input for a file name....
This program must be in java, use printf, and request user input for a file name. NameSubsLast3 (30 points) Write a program that does the following. Write a program that does the following. Requests the name of an input file and uses it to create an input file Scanner. Requests the name of an output file and uses it to create a PrintWriter. I have posted firstNames.txt and outNames.txt in the homework for Lesson 6. Calls createArray to create a...
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
MATLAB QUESTION Write a python program to request a positive float input from the user, x....
MATLAB QUESTION Write a python program to request a positive float input from the user, x. The program should check for the value of x. If x is larger than or equal to 1.0, the program should display the value of x in addition to the string “is larger than or equal to 1” and then terminate the program. If x is less than 1 the program should calculate y such that: y = 1-x+x^2/2-x^3/3+x^4/4-x^5/5……-x^99/99+x^100/100 The program should then display...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
create a program using IDLE where you will gather input from the user using a loop....
create a program using IDLE where you will gather input from the user using a loop. The user needs to provide you with a list of test scores for two categories (two different classrooms). Test scores must be integer values between 0 and 10. You need to process each score so that you can output the following: Number of test scores entered for classroom A. Number of test scores entered for classroom B. Average of test scores entered for classroom...
create a program using IDLE where you will gather input from the user using a loop....
create a program using IDLE where you will gather input from the user using a loop. The user needs to provide you with a list of test scores for two categories (two different classrooms). Test scores must be integer values between 0 and 10. You need to process each score so that you can output the following: Number of test scores entered for classroom A. Number of test scores entered for classroom B. Average of test scores entered for classroom...
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT