3 Replies - 1120 Views - Last Post: 16 April 2007 - 09:20 PM Rate Topic: -----

#1 bortiz0823  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-January 07

CHAR display problem

Posted 16 April 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.
 #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();
}


Is This A Good Question/Topic? 0
  • +

Replies To: CHAR display problem

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: CHAR display problem

Posted 16 April 2007 - 07:31 PM

Can you show what you mean? When I run the program, I get the following:

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#3 bortiz0823  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-January 07

Re: CHAR display problem

Posted 16 April 2007 - 07:43 PM

View Postbortiz0823, on 16 Apr, 2007 - 06:39 PM, said:

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.
 #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.
Was This Post Helpful? 0
  • +
  • -

#4 bortiz0823  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-January 07

Re: CHAR display problem

Posted 16 April 2007 - 09:20 PM

Ok, I resolved the problem. I add a strcpy for the name and done. Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1