Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Assignment Description: Write a program that calculate the Body Mass Index (

ID: 3573052 • Letter: C

Question

C++

Assignment Description:

Write a program that calculate the Body Mass Index (BMI). Your program should perform the following tasks:

Prompt the user to enter the following data for each person:

? ID (four digit integer),

? Name 20 character string,

? Weight in pounds (floating-point with 1 digit after decimal point),

? Height in inches (floating-point with 1 digit after decimal point).

ComputetheBMIusingthefollowingformula:
BMI = (weightInPounds * 703) / (heightInInches * heightInInches)

Save (Write) the input data (id, name, weight, height) and the calculated BMI (floating-point with 2 digits after decimal point) into a text file (e.g. bmifile.txt).

Repeat steps 1-3 to compute the BMIs for three persons, then close the text file.

Program Requirements:

The program must use streams, cout and cin objects to perform the IOs with

console, printer, and file, and use IO manipulators to format the output.

The program should include the following information as comment on top of source

code:

? Programming assignment number

? Author of the program

? Date of programming (or due date)

? Brief description on what the program will do

(floating-point lllput data (id, name, weight, height) and the ca with 2 digits after decimal point) into a text file (e. Repeat steps 1-3 to compute the for three persons, then Now, read all the BMI records from the text file, one person eac a summary like the following: D Name 1234 Ada Alexandra 176.0 70. 25.25 2408 Bobby Barnes 250.0 78.0 28.89 a Carlos 110.0 62 20. 12 ogram Requirements: The program must use streams, cout and cin objects to perfo console, printer, and file, and use IO manipulators to format the The program should include the following information as comme code: Programming assignment number Author of the program

Explanation / Answer

/ basic file operations
#include <iostream>
#include <fstream>
using namespace std;


int main () {
   std::ofstream myfile;
   myfile.open("bmifile.txt",std::ofstream::out | std::ofstream::app);
   myfile << "ID"<<" "<<"Name"<<" "<<"Weight"<<" "<<"Height"<<" "<<"BMI";
   myfile << "------"<<" "<<"------"<<" "<<"------"<<" "<<"------"<<" "<<"------";
  
   int count = 0;
   int ID;
   string Name;
   float Weight,Height,BMI;

   for(count=0; count<3; count++) {
       cout << "Enter ID: ";
       cin >> ID;
       cout << "Enter Name: ";
       cin >> Name;
       cout << "Enter Weight: ";
       cin >> Weight;
       cout << "Enter Height: ";
       cin >> Height;
       BMI = (Weight*703)/(Height*Height);
       myfile <<ID<<" "<<Name<<" "<<Weight<<" "<<Height<<" "<<BMI;
   }
   myfile.close();
   char str[255];
   ifstream readfile("bmifile.txt");
   while(readfile) {
       readfile.getline(str,255);
       cout << str << endl;
   }
   return 0;
}