Program output problem



  • I have written an application that takes user input and displays the output. Within the menu the user has option to choose a yes or no answer which would then provide feedback based on those options. I have written the head files and classes and the program runs but only provides part of the output.

    Any assistance would be greatly appreciated.

    It produces the following outputs:

    If yes is chosen

    Enter Product_Name:
    cisco
    Enter Product_Price:
    3333
    Enter Supplier_Name:
    john
    Enter Supplier_Email:
    mail.com
    Is the supplier a manufacturer (Y/N) :
    y

    Vendor name: - output missing
    Vendor email: - output missing
    Product Name: cisco
    Product Price: R3333
    Product Supplier: - output missing
    Press <RETURN> to close this window...

    2nd output - if no is chosen
    Enter Product_Name:
    cisco
    Enter Product_Price:
    44444
    Enter Supplier_Name:
    john
    Enter Supplier_Email:
    mail.com
    Is the supplier a manufacturer (Y/N) :
    n

    Product Name: cisco
    Product Price: R44444
    Product Supplier: - output missing
    Press <RETURN> to close this window...

    Product.h

    @#ifndef PRODUCT_H
    #define PRODUCT_H

    #include "Vendor.h"
    #include <QString>

    class Product {

    private:
    QString m_Name;
    double m_Price;
    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@

    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@

    Main.cpp

    @#include <QCoreApplication>
    #include "Vendor.h"
    #include "Product.h"
    #include <QString>
    #include <QDebug>
    #include <QTextStream>

    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();
    

    @

    I believe my problem is in one of these functions

    Product.cpp

    @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;
               }
    

    }
    @

    Vendor.cpp

    @or this one

    void Vendor::setDetails(QString name, QString email, bool isManufacturer){

    m_Name = name;
    m_Email = email;
     m_IsManufacturer = isManufacturer;
    

    }

    bool Vendor::isManufacturer (){
    return m_IsManufacturer;
    }

    @


  • Lifetime Qt Champion

    Hi,

    You're main being incomplete, the error can't be easily spotted. Can you show the complete main function ?



  • Main.cpp

    @#include <QCoreApplication>
    #include "Vendor.h"
    #include "Product.h"
    #include <QString>
    #include <QDebug>
    #include <QTextStream>

    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;
                }
                else{
                    supplierIsManufacturer = false;
                }
    
    
    
              Vendor vendor;
               Product product (product_Name, productPrice);
                vendor.setDetails(supplier_Name, supplier_Email, supplierIsManufacturer);
    
                    cout << product.toString(supplierIsManufacturer) << endl;
    
    return 0;
    

    }
    @

    Product.cpp

    @#include "Product.h"
    #include"Vendor.h"
    #include<QString>

    Product::Product (QString name, double price) {

    m_Name = name;
    m_Price = price;
    

    }

    void Product::setSupplier(QString name, QString email, bool isManufacturer){

    Vendor vendor;
        vendor.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;
               }
    

    }

    @

    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;
    }

    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 ;
    
        }
    

    }

    @


  • Lifetime Qt Champion

    What output are you expecting ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.