I am using Visual Studio, 2015, and need help with this C++ code. The aim is to show a basic example of a Class using it's own Header file and to return three values. This code we are not using #pragma, is that an issue?
//#pragma once
#include "stdafx.h"
#include <iostream>
#include <string>
usingnamespace std;
#ifndef BMI_H
#define BMI_H
class BMI {
public:
// default constructor just to set member variables to null states
BMI();
BMI(string, int, double);
//destructor
~BMI();
//Below are the accesor functions which return member variables
//typicaly we use get in front as a universal way to identify it
string getName() const;
int getHeight() const;
double getWeight() const;
private:
//Member variables
string newName;
int newHeight;
double newWeight;
};
#endif
//accesor functions are used to access information from member variables
#include "stdafx.h"
#include <iostream>
#include <string>
#include "BMI.h"
usingnamespace std;
int main()
{
string name;
int height;
double weight;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your height in inches: ";
cin >> height;
cout << "Enter your weight in pounds: ";
cin >> weight;
//BMI Student_1; //the object uses the default constructor
//below if you want to also use overload constructor
BMI Student_1(name, height, weight);
cout << endl << "Patients name: " << Student_1.getName() << endl <<
"Height: " << Student_1.getHeight() << endl <<
"weight: " << Student_1.getWeight() << endl;
return 0;
}
Severity Code Description Project File Line Suppression State
Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? BMI.main c:\users\logan\documents\visual studio 2015\projects\bmi.main\bmi.main\bmi.cpp 37
Place your code within [code] [/code] tags. For example, the input [code]int main() { std::cout << "Hello World\n"; }[/code]
Produces int main() { std::cout << "Hello World\n"; }