This looks like a lot but it really is not. I have three files listed below (mai
ID: 3647195 • Letter: T
Question
This looks like a lot but it really is not. I have three files listed below (main, implementation, and header) and I am wondering how to combine them all together to produce the result my assignment is asking for? I am not able to get anything to compile and I am not sure how to set it up for everything to work.Assignment Description:
1) Create an implementation file for a class called PhoneData.
2) Create a file to test the class.
Class Description:
The class has 2 data members:
string name;
string phoneNumber;
The class has the following constructors and member functions:
A default constructor that initializes the 2 data members to "".
A 2 parameter constructor that assigns the parameter values to the data members.
2 mutator (set) and 2 accessor (get) functions, listed below
void setName(string n);
void setPhoneNumber(string pN);
string getName() const;
string getPhoneNumber() const;
I've created the class specification file for you (.h header file). Do Not change this file. It's attached (PhoneData.h). You will need to download and add it to your project (in the "Header Files" folder of your solution).
You will need to create 2 files.
1) The implementation file (The file where you define the class constructors and member
functions. A .cpp file)
2) The file that contains code to test your class (has the main function). A .cpp file.
Name the 2 files as follows:
PhoneData.cpp // PhoneData implementation file
PhoneDataMain.cpp // main file
Be sure you save all 3 files in the same folder on your hard drive. For example if you saved the header file (.h) to a folder called c:MyFiles, than you need to put the above files in the same folder. That way when you compile your implementation and test files, the compiler will be able to locate the .h header file that you listed in the include directive.
To test your class create the main file as follows:
Create 2 PhoneData objects and assign values to data members.
For example, when creating your objects do the following:
PhoneData pd1("Susan Meyers", "414 444-4444");
PhoneData pd2("Joy Rodgers", "888 888-8888");
From main, use the get (accessor) functions to display the class data.
Attached is an example of the programs output.
The best way to do this assignment is start by creating the implementation file. Once you have that finished (a clean compile), create the file that tests the class (has the main file in it).
// PhoneDataMain.cpp
#include "PhoneData.h"
//main function
int main()
{
//two PhoneData objects
PhoneData pd1("Susan Meyers", "414 444-4444");
PhoneData pd2("Joy Rodgers", "888 888-8888");
//displaying objects details using getter functions
//PhoneData1
cout<<" Phone Data 1: "<<endl;
cout<<" Name: "<<pd1.getName()<<endl;
cout<<"Phone Number: "<<pd1.getPhoneNumber()<<endl;
//PhoneData2
cout<<" Phone Data 2: "<<endl;
cout<<" Name: "<<pd2.getName()<<endl;
cout<<"Phone Number: "<<pd2.getPhoneNumber()<<endl;
cout<<endl;
system("pause");
return 0;
} //end of the main
// PhoneData.cpp
#include "PhoneData.h"
//no argument constructor
PhoneData ::PhoneData()
{
//initializes both data members to empty strings
name = "";
phoneNumber = "";
}
//two argument constructor
PhoneData ::PhoneData(string name,string number)
{
//initializes both variables with appropriate
//passed arguments
this->name = name;
phoneNumber = number;
}
//setter method for name
void PhoneData :: setName(string name)
{
this->name = name;
}
//setter method for phoneNumber
void PhoneData :: setPhoneNumber(string number)
{
this->phoneNumber = number;
}
//getter method for name
string PhoneData :: getName() const
{
return name;
}
//getter method for PhoneNumber
string PhoneData :: getPhoneNumber() const
{
return phoneNumber;
}
// PhoneData.cpp
#include "PhoneData.h"
//no argument constructor
PhoneData ::PhoneData()
{
//initializes both data members to empty strings
name = "";
phoneNumber = "";
}
//two argument constructor
PhoneData ::PhoneData(string name,string number)
{
//initializes both variables with appropriate
//passed arguments
this->name = name;
phoneNumber = number;
}
//setter method for name
void PhoneData :: setName(string name)
{
this->name = name;
}
//setter method for phoneNumber
void PhoneData :: setPhoneNumber(string number)
{
this->phoneNumber = number;
}
//getter method for name
string PhoneData :: getName() const
{
return name;
}
//getter method for PhoneNumber
string PhoneData :: getPhoneNumber() const
{
return phoneNumber;
}
#ifndef PHONE_DATA_H
#define PHONE_DATA_H
#include <iostream>
#include <string>
using namespace std;
/******* Class PhoneData Specification ********/
class PhoneData
{
private:
string name;
string phoneNumber;
public:
// 2 parameter constructor
PhoneData(string, string);
// defualt constructor
PhoneData();
// mutator functions
void setName(string);
void setPhoneNumber(string);
// accessor functions
string getName() const;
string getPhoneNumber() const;
};
#endif
Explanation / Answer
Its not the answer, its just a hint for you, thanx Dear you can do it with "Makefile" in C++ CC = g++ CFLAGS = -I/home/scale/g++Projects/gLib/ LDFLAGS = -lfltk all: octhecdec clean octhecdec: octhecdec.o $(CC) -o $@ $^ $(LDFLAGS) octhecdec.o: octhecdec.cpp octhecdec.h $(CC) -c $(CFLAGS) $< .PHONY: clean cleanest clean: rm *.o cleanest: clean rm octhecdec $@ name of the target $^ name of all prerequisites with duplicates removed $Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.