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.
1) 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
2)
be a global variable.
Declare an array of 9 of the structures in #1. This array should
3) Initialize each of the file numbers in the array to -1.
4) 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.
5) 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.
6) If the user provides a diagnosis number that is not between 1
and 8, ask again.
7) Store the data in the array of structures in the order it is provided.
8) 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.
9) 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.
10) 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
#include<iostream>
using namespace std;
struct imageData
{
int fileNum;
int diagNum;
int numLayers;
float maxAvgIntensity;
};
imageData arrayImageData[9];
int countRecords=0;
/* function to print data for the given file number */
/* if found diplay data and return 1*/
/* if not foud return 1*/
int printImageData(int fileNum)
{
for (int i = 0; i < countRecords; i++)
{
if (arrayImageData[i].fileNum == fileNum)
{
cout << "\nRequired data is as below :: ";
cout << "\nFile Number :: " << arrayImageData[i].fileNum;
cout << "\nDiagnosis Number :: " << arrayImageData[i].diagNum;
cout << "\nNumber of Layers :: " << arrayImageData[i].numLayers;
cout << "\nMaximum Average Intensity :: " << arrayImageData[i].maxAvgIntensity;
return 1;
}
}
return 0;
}
int main()
{
int reqfileNum;
/* Initialize all file numbers with -1*/
for (int i = 0; i < 9; i++)
{
arrayImageData[i].fileNum = -1;
}
/* get details for 9 image data from user */
for (int i = 0; i < 9; i++)
{
cout << "Enter Details for Image Data #" << i << endl;
cout << "Enter File Number(>0) :: ";
while (1) /* infinite loop to repeatedly ask for file number until entered file number is greater than equal to 0 */
{
cin >> arrayImageData[i].fileNum;
if (arrayImageData[i].fileNum >= 0)
break;
cout << "File Number should be greater than 0. Enter Again :: ";
}
if (arrayImageData[i].fileNum == 0)
break;
cout << "Enter Diagnosis Number (Between 1 & 8) :: ";
while (1) /* infinite loop to repeatedly ask for diagnosis number until entered diagonis number is between 1 and 8 */
{
cin >> arrayImageData[i].diagNum;
if (arrayImageData[i].diagNum >= 1 && arrayImageData[i].diagNum <=8)
break;
cout << "Diagnosis Number should be between 1 and 8. Enter Again :: ";
}
cout << "Enter Number of layers in image :: ";
cin >> arrayImageData[i].numLayers;
cout << "Enter Maximum Average intensity :: ";
cin >> arrayImageData[i].maxAvgIntensity;
cout << endl << endl;
countRecords++;
}
/* infinite loop to repeatedly ask for file number to be searched. Break if file number not found */
while (1)
{
cout << "\nEnter File Number for which information needs to be displayed :: ";
cin >> reqfileNum;
int retVal = printImageData(reqfileNum);
if (retVal == 0)
break;
cout << endl;
}
/* function to display all records*/
for (int i = 0; i < countRecords; i++)
{
cout << "\nData for Record #"<<i+1;
cout << "\nFile Number :: " << arrayImageData[i].fileNum;
cout << "\nDiagnosis Number :: " << arrayImageData[i].diagNum;
cout << "\nNumber of Layers :: " << arrayImageData[i].numLayers;
cout << "\nMaximum Average Intensity :: " << arrayImageData[i].maxAvgIntensity;
cout << endl;
}
return 0;
}
Both the above screenshots are in continuation.
Please upvote if u like answer