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.

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

  1. 3) Initialize each of the file numbers in the array to -1.

  2. 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

Solutions

Expert Solution

#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


Related Solutions

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...
In C: You are to create a program to request user input and store the data...
In C: 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...
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...
Q1 Create a program that asks the user to input their budget. Then, it will ask...
Q1 Create a program that asks the user to input their budget. Then, it will ask the user to input each of their purchase until their entire budget is used up. What kind of loop do you think is the most appropriate? You don't have to create the entire program. Part of it has already been created for you (see code below). Note: Assume that the user always uses up their budget to the last cent and they don't over...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT