(Solved) I can't figure how to get started on my Program 4 project. Coding

Posted on : by : admin

$ 29.00

I can't figure how to get started on my Program 4 project. Coding

SKU: 8023

Description

  

I can’t figure how to get started on my Program 4 project. Coding for my Program 3 is at the end. Attached is also a text file containing five line of weight and height respectively.

 

Write a computer program as a 32-bit console application in C as an extension to Program 3 to process a series of weights and heights, and producing the number of persons in each of the four BMI categories from the given input data file. Your program shall count and print the number of underweight (BMI < 18.5), the number of normal (18.5 – 24.9), the number of overweight (25.0 – 29.9), and the number of obese (BMI > 30.0) persons on the screen. After all the input data has been read, display the results on the computer screen, with headers for each BMI category, and the count for each category underneath. Data in the input file will be whole numbers.

The name of your source program shall be p4.c and that of your corresponding executable program shall be p4.exe.

Your program shall receive information from the user as a command-line argument. For example, a typical command line to start your program (from a command prompt) might be C:>p4 bmi_datafile.txt

Your program shall NOT seek information from the user such as by a call to scanf().

Your program shall NOT print information to the screen except as required herein.

If your program is started without any command-line arguments, it shall print the following line to the screen and terminate execution: Project P4, <your ID>, <your name>.

? If your program is started with at least one command-line argument, it shall NOT print the line given above but shall proceed with normal execution.

? The first command-line argument (after the program name itself) will be the name of the text file for your program to read. A properly formatted input file will contain int (integer) numbers, separated from each other by a space, a newline, or a tab.

? If the file supplied as a command-line argument cannot be opened, your program shall write an error message to the screen and terminate execution. In a similar manner, your program shall properly handle all error conditions that might arise.

? When you have successfully opened the input file inside main, you shall pass processing to a separate function called process_file. This function shall have a return type of void, with five arguments: namely an input file pointer named infilep, and four output pointers; int *underp, int *normp, int *overp, and int *obesep (in that order when the function is called).

? Your program shall read the input text file and count the number of numbers, and then print the categorized results in tabular form. The final results shall be printed from main.

? After your program has read and processed the entire file, it shall print the following output to the screen containing the various totals, as defined above. <file name> contains <number items>, and the table of results follows:

Under(<18.5)         Normal(18.5 – 24.9)             Over(25.0 – 29.9)               Obese(>30.0)

   <value>                           <value>                                 <value>                              <value>

Coding for Program 3

/* Name: main */
int
main(int argc, char *argv[])
{
FILE *inp; /* File pointer */
int weight; /* Weight of the user in pounds */
int height; /* Height of the user in inches */
double bmi; /* Body Mass Index of the user */

if (argc
{
printf(“Project P3, ID, Name n”, argv[0]);
exit(0);

}

else if(argc >=2)
{
inp = fopen(argv[1], “r”);

if (inp == NULL)
{printf(“File cannot be opened. Program ending. n”);
exit(0);
}
else
{
/*Scan the numbers from text file to find weight and height.*/
fscanf(inp, “%d %d”, &weight, &height);

fclose(inp);
/*Turn the integers (int) into double. Calculate the BMI*/
bmi = ((double) 703.0 * weight)/((double) height * height);
if (bmi {
printf(“Input data: Weight = %d pounds, Height = %d inches. “, weight, height);
printf(“Your BMI is %.1lf, and you are categorized as underweight. n”, bmi);
}
else if(bmi >= 18.5 && bmi {
printf(“Input data: Weight = %d pounds, Height = %d inches. “, weight, height);
printf(“Your BMI is %.1lf, and you are categorized as normal. n”, bmi);
}
else if(bmi >= 25.0 && bmi {
printf(“Input data: Weight = %d pounds, Height = %d inches. “, weight, height);
printf(“Your BMI is %.1lf, and you are categorized as overweight. n”, bmi);
}
else if (bmi > 30.0)
{
printf(“Input data: Weight = %d pounds, Height = %d inches. “, weight, height);
printf(“Your BMI is %.1lf, and you are categorized as obese. n”, bmi);
}

}

}
return(0);
}

155 73 155 73 155 73 200 78 275 73