Question: Consider the partial implementation of the class BmiViewer, which allows the user to enter height in meters and weight in kilograms and returns the calculated

Consider the partial implementation of the class BmiViewer, which allows the user to enter height in meters and weight in kilograms and returns the calculated BMI (body mass index):
BmiViewer declaration (partial content of bmiviewer.h)
#ifndef BMIVIEWER_H
#define BMIVIEWER_H
#include
#include
#include
#include
#include
#include
#include
class BmiViewer : public QWidget {
Q_OBJECT
public:
BmiViewer();
void calculateBmi(); private:
QLineEdit* heightEntry; QLineEdit* weightEntry; QErrorMessage* error;
};
#endif
BmiViewer definition (partial content of bmiviewer.cpp)
#include "bmiviewer.h"
BmiViewer::BmiViewer(){
setWindowTitle("BMI Calculator");
QGridLayout* layout = new QGridLayout(this);
QLabel* inputWeightRequest = new QLabel("Enter weight in kilograms ");
weightEntry = new QLineEdit();
QLabel* inputHeightRequest = new QLabel("Enter height in meters ");
heightEntry = new QLineEdit();
setDecMode();//for setting the LCD number mode setSegmentStyle(QLCDNumber::Flat);//for setting LCD style
layout->addWidget(inputWeightRequest,0,0);
layout->addWidget(weightEntry,0,1);
layout->addWidget(inputHeightRequest,1,0);
layout->addWidget(heightEntry,1,1);
setLayout(layout);
}
void BmiViewer::calculateBmi(){}
content of main.cpp
#include
#include "bmiviewer.h"
int main(int argc, char* argv[]){
QApplication app(argc, argv); BmiViewer b;
b.show();
return app.exec();;}
Complete the implementation of the class BmiViewer (both header and cpp files) so that
it produces the following output:
when the user enters the weight and height in the above Graphical User Interface (GUI) and clicks the Calculate button, it calculates the BMI as weight/(heightheight) and displays the result in the LCD number widget.
if the user enters a non-number in either of the QLineEdits, it displays an error message as shown below:
Note: You only need to write down the lines of code that are required to complete the implementation. Indicate where the additional code must be added (in both header and cpp files). However, for the function calculateBmi()you must write down the complete implementation.(12)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!