
” Comp 218/EC编程 写作、C++编程Concordia UniversityComp 218/EC Winter 2021Fundamentals of Object Oriented ProgrammingAssignment 4 – Due by 11:59pm Friday April 16th, 2021______________________________________________________________________________PURPOSE: This assignment will give you the opportunity to write the declaration for a structureand use it, to define and use a class, and manipulate a one-dimensional array.Specifications for programming:- Refer to handout for Assignment #1Question #1: Writing a structure declaration (4 pts)a) Declare a struct type named Pet which will describe a pet. The following informationshould be Included:Name (string of characters)Age (double number)Breed (string of characters)Gender (string of characters)isAdopted (boolean)b) Declare pet1 to be a variable of type Pet.c) Write a function to read values into the member variables of type Pet. (The structvariable should be passed as an argument). The order in which the data is read is thesame as that in the struct.d) Display all the values in your program.Following is a sample output screens to illustrate the expected behavior of your program.Users input is highlighted with a red circle.Comp 218/Winter 2021 Page 2 of 7 Assignment #4Figure 1: Output Example of Question 1Question #2: Implementing a class (11 pts)a) (2 pts) A Pet object represent the name, age, breed and gender for a pet. Write adeclaration for the Class Pet including its data members and function members based onthe following UML and save it in a file called Pet.h.Comp 218/Winter 2021 Page 3 of 7 Assignment #4b) (5 pts) Implement the member functions based on the following descriptions, and save themin a file called Pet.cpp. Pet(): default constructor, which will set all the attributes to kitty, 2.5,BritishShorthair, female, true. Pet (string name): a name constructor which sets the attribute name to the passedvalue and the other three attributes age, breed , gender, isAdopted will be thedefault one, which are 2.5, BritishShorthair, female, true. Pet (string name, double date, string breed, string gender, boolchoice): a third constructor which sets all the attributes to the passed values. getName(): returns the name of the item. getAge(): returns the age of the pet. getBreed(): returns the breed of the pet. getGender(): returns the gender of the pet. getAdoption(): return the adoption status of the pet. setName(string n): sets the name attribute to n. setAge(double a): sets the age attribute to a. setBreed(string b): sets the breed attribute to b. setGender(string g): Sets the gender attribute to g. setAdoption (boolean choice): sets the adoption status of the pet. inHumanYears(): which will return the age of a pet cat in human years. Here is how tocalculate it:a. 18 human years equals the first year of a medium-sized cats life.b. Year two for a cat equals about nine years for a human.c. And after that, each human year would be approximately five years for a cat.Here a few examples:Pet- name: string- age: double- breed: string- gender: string- isAdopted: boolean+ Pet ()+ Pet (string n)+ Pet (string n, double a, string b, string g, bool choice)+ getName(): string+ getAge(): double+ getBreed(): string+ getGender(): string+ getAdoption(): boolean+ setName(string n):void+ setAge(double a): void+ setBreed(string b): void+ setGender (int g): void+ setAdoption (bool choice): void+ inHumanYears(): double+ equals(Pet p): boolean+ printInfo():voidComp 218/Winter 2021 Page 4 of 7 Assignment #4a. 4-month old cat = .25 (which is of a year) * 18 = 4.5 human yearsb. a 5 years old = 18 + 9 + (5-2) * 5 = 42 human years equals(Pet p): returns true if the name, age, breed , gender, isAdopted of thecalling object are the same, otherwise return false. printInfo(): displays on the console the name, age, breed , gender, isAdopted.(see the Example below)c) (3 pts) Write a program name A4Q2.cpp that uses the class Pet as follows: Create an object pet1 using the default constructor. Create an object pet2 using the second constructor. Prompt the user for the name.Assume the user enters valid input. Create an object pet3 using the third constructor. Prompt the user for the name, age,breed, gender and isAdopted. Assume the user enters valid inputs. Display the info of three objects following the format shown in the example shownbelow. Calculate the 3 Objects age in human years and display the result. Change the age of the second object pet2 which equals to the sum of pet1s age andpet3s age and display pet2s new age in human years. Compare the 3 objects (pet1, pet2 pet3) and indicate whether they are equal. Seeformat of message in the sample output at the end of this question. End with a closing message.NOTE : Be sure to save the class declaration in a header file Pet.h, the class implementation ina Pet.cpp file. Dont forget to include these files in the project.Following is a sample output screens to illustrate the expected behavior of your program.Users input is highlighted with a red circle.Comp 218/Winter 2021 Page 5 of 7 Assignment #4Figure 2: Output Example of Question 2Question #3: Array implementation (5 pts)In this question, assuming a building has 20 rooms and 20 security guards. All rooms are closedon the weekends. Every Monday, the first security guard, denoted S1, opens every room. Thenthe second security guard, S2, begins with the second room, denoted R2, and closes every otherroom. Security guard S3 begins with the third room and changes every third room (closes it if itwas open, and opens it if it was closed). Security guard S4 begins with room R4 and changes everyfourth room. Security guard S5 starts with R5 and changes every fifth room, and so on, untilsecurity guard S20 changes R20.After all the security guards have passed through the building and changed the rooms, whichrooms are open? You are Required to use one dimensional array to find the answer. TheComp 218/Winter 2021 Page 6 of 7 Assignment #4program should display as following:Figure 3: Output of Question 3What to Hand in for Assignment 4Be sure to test your programs in Visual Studio.- Zip the word file from question 1, the .h and two .cpp files for question 2 and the .cpp file forquestion 3.- Naming convention for zip file: Create one zip file , containing all source files for yourassignment using the following naming convention:The zip file should be called a#_studentID, where # is the number of the assignmentstudentID is your student ID number. So for the fourth assignment, student 123456would submit a zip file named a4_123456.zip.Evaluation Criteria for Assignment 4Question 1/4 ptsPart a) 1 ptPart b) 1 ptPart c) 1 ptPart d) 1 ptQuestion 2/11 ptsHeader file (pet.h) 2 ptsImplementation of class (pet.cpp) 5 ptsWriter main program using class Pet 3 pts- Comments/identifier names- Choice of variable names- description of Variables- description of functions and steps in mainprogram1 ptComp 218/Winter 2021 Page 7 of 7 Assignment #4Question 3/5 pts- Comments/identifier names- Choice of variable names- description of variables- description of the steps in code1 ptStore data into array 2 ptsSave and display data from the array 2 ptsTOTAL 20 ptsPrograms were tested in Visual Studio and zipped assuggested in the two How-to documents on theassessments page.2 pts (not included in 20 pts)Note: If Assignment format is notas requested, a perfectassignment could Result in a finalgrade of 18/20请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。





