Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Program output problem
Qt 6.11 is out! See what's new in the release blog

Program output problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aquanaut
    wrote on last edited by
    #1

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

    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aquanaut
        wrote on last edited by
        #3

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

        }

        @

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What output are you expecting ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved