3. #include <iostream>
using namespace std;
class DayOfYear{
public:
friend bool equal(DayOfYear date1, DayOfYear
date2);//a friend function that compares two objects
//yes: if date1 is
the same as date2; no: otherwise
DayOfYear();//default constructor: 1/1/2009
DayOfYear(int new_day, int new_month, int
new_year);//
void output() const; //
int get_day(); // return the value of "day"
int get_month();
int get_year();
void set_DayOfYear(int new_day, int new_month, int
new_year); //new_day-->day, new_month->month, new_year--
>year
void set_day(int new_day); // day-->new_day
void set_month(int new_month);
4. void set_year(int new_year);
private:
int day;
int month; //int --> char *
int year;
};
#endif //
Q2/person.cppQ2/person.cpp/*
Name: person.cpp
Copyright:
Author:
Date: 22/02/09 14:35
Description: declaration of a new class DayOfYear
*/
#include"person.h"
Person::~Person()
{
if( emails != NULL ){
delete[] emails;
emails = NULL;
}
}
5. Person::Person()
{
id =-1;
name ="NA";
//birthday = DayOfYear( 1,1, 2000);
emails = NULL;
numEmails =0;
}
Person::Person(int new_id, string new_name,DayOfYear date)
{
id = new_id;
name = new_name;
//birthday = date;
emails=NULL;
numEmails=0;
}
/**/
Person::Person(constPerson& someone)
{
id = someone.id;
name = someone.name;
birthday = someone.birthday;
numEmails = someone.numEmails;
//allocate space to *emails if numEmails>0
if(numEmails ==0)
emails = NULL;
else{
emails =new string [numEmails];
for(int i=0;i<numEmails; i++)
emails[ i ]= someone.emails[ i ];
}
}
/**/
6. /**/
voidPerson::operator=(constPerson& rhs)
{
id = rhs.id;
name = rhs.name;
birthday = rhs.birthday;
//allocate space to *emails if needed
if(numEmails >0)
delete[] emails;//release the old memory
numEmails = rhs.numEmails;
emails =new string [numEmails];
for(int i=0;i<numEmails; i++)
emails[ i ]= rhs.emails[ i ];
}
/**/
voidPerson::output()const
{
// id = 200;
cout <<"--------------------------n";
cout <<" id="<<(*this).id <<" name="<<this-
>name <<" birthday=";
birthday.output();
for(int i=0; i<numEmails; i++)
cout <<"email-#"<< i <<": "<< emails[i];
cout <<"n--------------------------nn";
}
intPerson::get_id()const
{
return id;
}
8. //case 1: emails list is empty
if( numEmails ==0){
emails =new string[1];
//verification
emails[0]= the_email;
}
else{//case 2: expand the list
string *tmp_emails=new string [numEmails];
for(int i=0; i<numEmails; i++)//save the emails
tmp_emails[i]= emails[ i ];
delete[] emails;
emails =new string [numEmails+1];//expand the list by o
ne
//verify the above allocation
for(int i=0; i<numEmails; i++)
emails[ i ]= tmp_emails[ i ];//copy the existing emails
emails[ numEmails ]= the_email;// add the new email
delete[] tmp_emails;
}
numEmails +=1;
}
intPerson::get_num_emails()const
{
return numEmails;
}
void print(constPerson& someone)
{
cout <<"****"<<someone.get_id()<<" "<< someone.get_nam
e()<<endl;
}
//perform a sequential search on the studentList
10. using namespace std;
class Person{
public:
//equalID() returns true:have the same ID; false:
otherwise
friend bool equalID(const Person & person1, const
Person &Person2);//
~Person(); //destructor: to release any memory that has
been allocated to the object
Person(); //default constructor: id=-1, name="NA",
birthday="1/1/2000"
Person( int new_id, string new_name, DayOfYear date);
//constructor that initializes
//id to new_id, name to new_name, and
birthday to date
Person(const Person & someone); //copy constructor:
construct a new object as a copy of "someone"
void operator= (const Person &rhs); //assign the object
on the right-hand-side to the left-hand-side
virtual void output() const; //print out a person's info.
11. int get_id() const; //return the id of a Person object
string get_name() const; //return the name of a Person
object
const DayOfYear get_birthday() const; //return the
birthday of a Person object
string getEmail( int i) const; //return the i-th email if
exists; o.w: return "NA"
void set_id(int new_id); //change a person's id to
new_id
void set_name(string new_name); // change a person's
name to new_name
void set_birthday(DayOfYear new_Date); //change a
person's birthday to new_date
void add_email( string the_email); //add the_email to
the list
int get_num_emails() const;
private:
int id;
string name;
DayOfYear birthday;
string *emails; //list of email addresses
int numEmails;
12. };
void print( const Person& someone); //print out a person's id
and name
bool sameID(const Person& person1, const Person&
person2);//true:have the same ID; false: otherwise
//search whether there exists a student on the studentList with
id=key
bool searchStudent( Person *studentList, int num_students, int
key);
#endif
Q2/personnel.cppQ2/personnel.cpp/*
Name: personnel.cpp
Copyright:
Author:
Date: 22/02/09 15:02
Description: manage a personnel database that currently consis
ts of one employee Mary
*/
#include"dayOfYear.h"
#include"person.h"
#include"student.h"
int main()
{
14. /**the code below create a dynamic array of Person
***
//1 & 2:
Person *students213 = NULL; //
int num = 200; //size of the dynamic array *students213
//3. allocate memory to students213
students213 = new Person [ num ];
//4. verify
if (students213 == NULL ){
cerr << "Memory allocation failure.n";
exit( -1 );
}
//5: use
for (int i=0; i<num; i++){
students213[ i ].set_id( i + 100);
students213[ i ].output();
}
//search based on id
cout << "Is there a student with ID=207? ";
if (searchStudent( students213, num, 207) )
cout << " Yes."<<endl;
else
cout << " No. "<<endl;
cout << "Is there a student with ID=507? ";
if (searchStudent( students213, num, 507) )
cout << " Yes."<<endl;
else
cout << " No. "<<endl;
//6&7: release the memory
delete [] students213;
students213 = NULL;
15. *****
**end of the dynamic array students213
**************************************/
return0;
}
Q2/student.cppQ2/student.cpp//File name--
student.cpp: implementation file for the Student class
#include"student.h"
//#include "dayOfYear.h"
//destructor
Student::~Student()
{
if(grades != NULL ){
delete[] grades;
}
}
//default constructor
Student::Student():Person()
{
//call the constructor of the base class to initialize the inherited
members
level =1;//freshmen
num_grades =0;
grades = NULL;
}
//a second constructor
Student::Student(int new_id, string new_name,DayOfYear date,i
nt lvl):Person(new_id, new_name, date),level(lvl),num_grades(0
),grades(NULL)
{
//call the corresponding constructor in the
16. //base class to initialize the inherited members
/* level = lvl;
num_grades = 0;
grades = NULL;
*/
}
//copy constructor
Student::Student(constStudent& std):Person(std)//call the copy
constructor of the base class
{
level = std.level;
num_grades = std.num_grades;
if(num_grades <=0)
grades = NULL;
else{//allocate space to *grades and copy the grades from std
(*this).grades =newdouble[ num_grades ];
if(grades == NULL ){
cerr<<"Student:Student(const Student &): Memory alloc
ation errorn";
exit(-1);
}
for(int i=0; i<num_grades; i++)
grades[ i ]= std.grades[ i ];
}
}
voidStudent::operator=(constStudent& rhs)
{
(*this).Person::operator=(rhs);
level = rhs.level;
if(num_grades != rhs.num_grades){
delete[] grades;
num_grades = rhs.num_grades;
grades =newdouble[ num_grades ];
21. void set_num_grades( int num); //num->num_grades,
allocate memory to *grades
void set_grade(int i, double grd); //grd --> grades[i]
friend ostream & operator <<( ostream & out, const
Student& std);
virtual void output() const; //print out a student's info.
private:
int level; //1-4: freshmen, sophomore, junior and senior
int num_grades;
double *grades;
};
#endif //_STUDENT_H
Q1/9.cpp
#include <iostream>
#include "figure.h"
#include "rectangle.h"
#include "triangle.h"
22. using std::cout;
int main()
{
Triangle tri;
tri.draw();
cout << "nDerived class Triangle object calling" << "
center().n";
tri.center();
Rectangle rect;
rect.draw();
cout << "nDerived class Rectangle object calling" << "
center().n";
rect.center();
return 0;
}
Each topic must have 150+ words
23. Topic 1:
Cherie is an accountant for a large advertising agency. After
receiving notice of a prospective, large account, she thinks of a
creative advertising campaign and tells her idea to Charles, her
manager. Charles shoots down her idea and reminds her that her
job is accounting. Several days later, the design team visits
Charles and asks him for more details on his brilliant campaign
idea. Cherie realizes that the campaign being discussed is her
idea.
What does this outcome indicate about the communication
climate and power holding in the agency? If you were Cherie,
would you approach Charles about stealing your idea, or would
you show support for your manager? Why?
Topic 2:
When it comes to coworkers, why are strong interpersonal
relationships important in business?
How do you build and maintain those relationships while
keeping professionalism at the forefront?
What are some challenges you face in doing so?
What are the key factors upon which coworker relationships are
usually based? Tell us about your experiences.