Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,144 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,073 people online right now. Registration is fast and FREE... Join Now!




CHAR display problem

 
Reply to this topicStart new topic

CHAR display problem, constructor

bortiz0823
16 Apr, 2007 - 05:39 PM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2007
Posts: 21


My Contributions
Hi, I have a little problem displaying the CHAR world. All the code works but when display the CHAR[20], its display symbols. Any suggestion are welcome.
CODE
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
class SalesPeople;
class salesTransactions
{
    friend void Display(salesTransactions sale, SalesPeople ID);
    private:
        int m;
        int d;
        int y;
        double  a;
        int id;
    public:
        salesTransactions( int month,  int day,  int year, double  amount,  int salesPersonId);
        static char slash[50];
};
char salesTransactions::slash[50] = "/";
salesTransactions::salesTransactions( int month,  int day, int year,  double  amount,  int salesPersonId)
{
    m=month;
    d=day;
    y=year;
    a=amount;
    id=salesPersonId;
    
}
class SalesPeople
{
    friend void Display(salesTransactions sale, SalesPeople ID);
    private:
        int salesPersonid;
        char PersonName[10];
    public:
        SalesPeople(int salesId, char PersonName[10]);
};
SalesPeople::SalesPeople(int salesId, char PersonName[10])
{
    salesPersonid=salesId;
    PersonName[10];
}

void Display(salesTransactions sale, SalesPeople ID)
{
    cout<<"THE DATE OF SALE IS: ";
    cout<<setfill('0')<< setw(2) << sale.m<<sale.slash<<setw(2)<<sale.d<<sale.slash<<setw(2)<<sale.y % 100<<endl;
    cout<<"\nAMOUNT: $"<<sale.a<<endl;
    cout<<"\nSALES PERSON NAME: "<<ID.PersonName[10]<<endl;
    cout<<"\nID NUMBER: "<<ID.salesPersonid<<endl;
}
void main()
{
    salesTransactions info(11, 25, 2007, 24.95, 04321);
    SalesPeople person(3256, "Michael");
    Display(info, person);
    cin.get();
    cin.get();
}







User is offlineProfile CardPM
+Quote Post

Amadeus
RE: CHAR Display Problem
16 Apr, 2007 - 06:31 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Can you show what you mean? When I run the program, I get the following:



Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

bortiz0823
RE: CHAR Display Problem
16 Apr, 2007 - 06:43 PM
Post #3

New D.I.C Head
*

Joined: 28 Jan, 2007
Posts: 21


My Contributions
QUOTE(bortiz0823 @ 16 Apr, 2007 - 06:39 PM) *

Hi, I have a little problem displaying the CHAR world. All the code works but when display the CHAR[20], its display symbols. Any suggestion are welcome.
CODE
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
class SalesPeople;
class salesTransactions
{
    friend void Display(salesTransactions sale, SalesPeople ID);
    private:
        int m;
        int d;
        int y;
        double  a;
        int id;
    public:
        salesTransactions( int month,  int day,  int year, double  amount,  int salesPersonId);
        static char slash[50];
};
char salesTransactions::slash[50] = "/";
salesTransactions::salesTransactions( int month,  int day, int year,  double  amount,  int salesPersonId)
{
    m=month;
    d=day;
    y=year;
    a=amount;
    id=salesPersonId;
    
}
class SalesPeople
{
    friend void Display(salesTransactions sale, SalesPeople ID);
    private:
        int salesPersonid;
        char PersonName[10];
    public:
        SalesPeople(int salesId, char PersonName[10]);
};
SalesPeople::SalesPeople(int salesId, char PersonName[10])
{
    salesPersonid=salesId;
    PersonName[10];
}

void Display(salesTransactions sale, SalesPeople ID)
{
    cout<<"THE DATE OF SALE IS: ";
    cout<<setfill('0')<< setw(2) << sale.m<<sale.slash<<setw(2)<<sale.d<<sale.slash<<setw(2)<<sale.y % 100<<endl;
    cout<<"\nAMOUNT: $"<<sale.a<<endl;
    cout<<"\nSALES PERSON NAME: "<<ID.PersonName[10]<<endl;
    cout<<"\nID NUMBER: "<<ID.salesPersonid<<endl;
}
void main()
{
    salesTransactions info(11, 25, 2007, 24.95, 04321);
    SalesPeople person(3256, "Michael");
    Display(info, person);
    cin.get();
    cin.get();
}


Yup, The display show every things parfect but, on the SALES PERSON NAME (its suppose to be a name of the constructor) appears blank or symbols. I think that the problem is on the constructor.

User is offlineProfile CardPM
+Quote Post

bortiz0823
RE: CHAR Display Problem
16 Apr, 2007 - 08:20 PM
Post #4

New D.I.C Head
*

Joined: 28 Jan, 2007
Posts: 21


My Contributions
Ok, I resolved the problem. I add a strcpy for the name and done. Thanks
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month