C-string as parameter

I basically just want to know how to pass arrays into parameters of type char, For example my question is to implement and define a function of type char in a class (The underlined part the is the main question, the bold part is my answer.

Define a class PhoneCall that represents a phone call. This class has three member variables:
number, a C-string that holds the phone number (consisting of 10 digits) to which a call is placed
• length, an int representing the length of the call in minutes
• rate, a float representing the rate charged per minute.

In my class defintion i must have:
• A default constructor that initializes number to an empty string, length to 0 and rate to 0.
• An overloaded constructor that accepts a new phone number and sets length and rate both to 0.


I want to know if this is correct:
1
2
3
4
5
6
7
8
9
class phonecall
{
public:
  PhoneCall();
  Phonecall(char num[10])  //Is this correct?
private:
  char number;   //Is this correct or must it be char number[10]; ?
  string contact;
  string type;


and in the implementation:

Phonecall::Phonecall(): number(" "), length(0), rate(0)
{
}
PhoneCall::Phonecall(char num[10]): number{num[10]),length(0), rate(0)
{
}


and in the main function when declaring an object: (The overloaded constructor is used)

phonecall obj({1,2,3,4,5,6}); Is this example correct to change the c_string number?



I would change it to:

1
2
3
4
5
6
7
8
9
class phonecall
{
public:
  PhoneCall();
  Phonecall(char *num)  //Is this correct?
private:
  char *number;   //Is this correct or must it be char number[10]; ?
  string contact;
  string type;


A pointer can be used to access the elements of an array.
I need more help, are the constructors in the implementation correct, and the object declaration correct?
Topic archived. No new replies allowed.