Goodday ,
I have created an object in a private class and want to access that object in that classes function. It would seem that it is not working.
When I answer yes to manufacturer the output is missing name, email and product supplier. If I say no then product supplier is still missing.
Enter Product_Name:
test product
Enter Product_Price:
333
Enter Supplier_Name:
shops
Enter Supplier_Email:
email.com
Is the supplier a manufacturer (Y/N) :
y
Vendor name:
Vendor email:
Product Name: test product
Product Price: R333
Product Supplier:
Press <RETURN> to close this window...
Here is my code as I am not sure why I am getting this issue.
Thanks for the help
Product.h
#ifndef PRODUCT_H
#define PRODUCT_H
#include "Vendor.h"
#include <QString>
class Product {
private:
double m_Price;
//A vendor object
Vendor m_Supplier;
public:
Product
(QString name,
double price
);
QString toString
(bool supplierDetails
);
};
#endif // PRODUCT_H
#ifndef PRODUCT_H
#define PRODUCT_H
#include "Vendor.h"
#include <QString>
class Product {
private:
QString m_Name;
double m_Price;
//A vendor object
Vendor m_Supplier;
public:
Product (QString name, double price);
void setSupplier(QString name, QString email, bool isManufacturer);
QString getManufacturerName();
QString toString(bool supplierDetails);
};
#endif // PRODUCT_H
To copy to clipboard, switch view to plain text mode
Vendor.h
#ifndef VENDOR_H
#define VENDOR_H
#include <QString>
class Vendor {
private:
bool m_IsManufacturer;
public:
Vendor();
bool isManufacturer();
};
#endif // VENDOR_H
#ifndef VENDOR_H
#define VENDOR_H
#include <QString>
class Vendor {
private:
QString m_Name;
QString m_Email;
bool m_IsManufacturer;
public:
Vendor();
void setDetails(QString name, QString email, bool isManufacturer);
bool isManufacturer();
QString getName();
QString toString();
};
#endif // VENDOR_H
To copy to clipboard, switch view to plain text mode
Main.cpp
#include <QCoreApplication>
#include "Product.h"
#include"Vendor.h"
#include <QString>
#include <QDebug>
#include <QTextStream>
using namespace std;
int main(int argc, char *argv[])
{
double productPrice;
bool supplierIsManufacturer;
cout << "Enter Product_Name:" << endl;
product_Name = cin.readLine();
cout << "Enter Product_Price:" << endl;
product_Price = cin.readLine();
cout << "Enter Supplier_Name:" << endl;
supplier_Name = cin.readLine();
cout << "Enter Supplier_Email:" << endl;
supplier_Email = cin.readLine();
cout <<"Is the supplier a manufacturer (Y/N) : " << endl;
supplier_IsManufacturer = cin.readLine();
productPrice = product_Price.toDouble();
if(supplier_IsManufacturer.at(0).toLower() == 'y') {
supplierIsManufacturer = true;
}
Vendor m_Supplier;
Product product (product_Name, productPrice);
m_Supplier.setDetails(supplier_Name, supplier_Email, supplierIsManufacturer);
cout << product.toString(supplierIsManufacturer) << endl;
return 0;
}
#include <QCoreApplication>
#include "Product.h"
#include"Vendor.h"
#include <QString>
#include <QDebug>
#include <QTextStream>
using namespace std;
QTextStream cout(stdout);
QTextStream cin(stdin);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString product_Name;
QString product_Price;
double productPrice;
QString supplier_Name;
QString supplier_Email;
QString supplier_IsManufacturer;
bool supplierIsManufacturer;
cout << "Enter Product_Name:" << endl;
product_Name = cin.readLine();
cout << "Enter Product_Price:" << endl;
product_Price = cin.readLine();
cout << "Enter Supplier_Name:" << endl;
supplier_Name = cin.readLine();
cout << "Enter Supplier_Email:" << endl;
supplier_Email = cin.readLine();
cout <<"Is the supplier a manufacturer (Y/N) : " << endl;
supplier_IsManufacturer = cin.readLine();
productPrice = product_Price.toDouble();
if(supplier_IsManufacturer.at(0).toLower() == 'y') {
supplierIsManufacturer = true;
}
Vendor m_Supplier;
Product product (product_Name, productPrice);
m_Supplier.setDetails(supplier_Name, supplier_Email, supplierIsManufacturer);
cout << product.toString(supplierIsManufacturer) << endl;
return 0;
}
To copy to clipboard, switch view to plain text mode
product.cpp
#include "Product.h"
#include<QString>
Product
::Product (QString name,
double price
) {
m_Name = name;
m_Price = price;
}
void Product
::setSupplier(QString name,
QString email,
bool isManufacturer
){
m_Supplier.setDetails(name, email, isManufacturer);
}
QString Product
::getManufacturerName() {
if(m_Supplier.isManufacturer()) {
return m_Supplier.getName();
}
else {
return "Unknown";
}
}
QString Product
::toString(bool supplierDetails
){
dataout
= "\nProduct Name:\t\t" + m_Name
+ "\nProduct Price:\t\tR" + QString::number(m_Price
) + "\nProduct Supplier:\t" + getManufacturerName
();
if(supplierDetails) {
return m_Supplier.toString() + dataout;
}
else{
return dataout;
}
}
#include "Product.h"
#include<QString>
Product::Product (QString name, double price) {
m_Name = name;
m_Price = price;
}
void Product::setSupplier(QString name, QString email, bool isManufacturer){
m_Supplier.setDetails(name, email, isManufacturer);
}
QString Product::getManufacturerName() {
if(m_Supplier.isManufacturer()) {
return m_Supplier.getName();
}
else {
return "Unknown";
}
}
QString Product::toString(bool supplierDetails){
QString dataout;
dataout = "\nProduct Name:\t\t" + m_Name + "\nProduct Price:\t\tR" + QString::number(m_Price) + "\nProduct Supplier:\t" + getManufacturerName();
if(supplierDetails) {
return m_Supplier.toString() + dataout;
}
else{
return dataout;
}
}
To copy to clipboard, switch view to plain text mode
Vendor.cpp
#include"Vendor.h"
#include<QString>
Vendor::Vendor() {}
void Vendor
::setDetails(QString name,
QString email,
bool isManufacturer
){
m_Name = name;
m_Email = email;
m_IsManufacturer = isManufacturer;
}
bool Vendor::isManufacturer (){
return m_IsManufacturer;
}
{
return m_Name;
}
if( m_IsManufacturer ) {
return dataout = "\nVendor name:\t\t" + m_Name + "\nVendor email:\t\t" + m_Email ;
}
}
#include"Vendor.h"
#include<QString>
Vendor::Vendor() {}
void Vendor::setDetails(QString name, QString email, bool isManufacturer){
m_Name = name;
m_Email = email;
m_IsManufacturer = isManufacturer;
}
bool Vendor::isManufacturer (){
return m_IsManufacturer;
}
QString Vendor::getName()
{
return m_Name;
}
QString Vendor::toString(){
QString dataout;
if( m_IsManufacturer ) {
return dataout = "\nVendor name:\t\t" + m_Name + "\nVendor email:\t\t" + m_Email ;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks