SlideShare a Scribd company logo
1 of 9
Download to read offline
All programming assignments should include the name, or names, of the
students. This information should be placed in the introductory comments
section. The introductory comments should also contain the purpose of the
program. Clear, concise, commenting is an important skill to develop and
will be part of the grade for each program. Programs should be submitted
via Blackboard as “.cpp” source programs. Each member of a team should
submit a copy of the program.
The purpose of PSA 7 is practice our programming style and techniques on
a fairly simple real world example of an application. PSA7.cpp is a program
that analyzes various aspects of the clients at an animal shelter. Your task
is to fill in the three routines that provide the necessary information to the
main routine. You may not alter the code in main. You must use the
interfaces as defined.
The first two routines are almost trivial and the only thing that is special
about one of them is the need to use a persistent variable.
The third one, shotRecord is a bit challenging. You must determine if each
animal has had the correct shots. These are for Parvovirus, Rabies, and
Bordetella. One confusion factor here is that they could have also received
a shot for Leptospirosis; that is not a required shot. Further complicating
things is the fact that the only thing that is important is that they received
the shot; they may have received their inoculations in differing orders.
Programme it using "CODE::BLOCK and also use the main function below:
#include
#include
#include
#include
using namespace std;
#define numberSpecies 4
#define numberShots 3
enum species {dog, cat, bird, rabbit};
enum shots {Parvovirus, Rabies, Bordetella, Leptospirosis};
string outString;
struct animal
{
string name;
unsigned int stay;
enum species animalType;
enum shots status[numberShots];
};
int displayAnimal(struct animal *animal)
{
cout << "Name:tt" << animal->name << endl;
cout << "Species:t";
switch (animal->animalType)
{
case dog:
cout << "Dog";
break;
case cat:
cout << "Cat";
break;
case bird:
cout << "Bird";
break;
case rabbit:
cout << "Rabbit";
break;
default:
cout << "Unknown";
}
cout << endl;
cout << "Length of stay: " << animal->stay << endl << endl;
return 0;
}
double averageStay(struct animal *animal)
{
// Your code goes here.
// Hint you will need to use a type we have not used before.
}
int countPopulation(struct animal census[], enum species kindAnimal, unsigned int k)
{
unsigned int j, animalCount;
// Your code goes here.
return animalCount;
}
bool shotRecord(struct animal *animal)
{
unsigned int temp, m, shot;
temp = 0;
// Your code goes here.
// This is the trickiest one!
return (temp == 3) ? true: false;
}
int main()
{
#define censusSize 6
struct animal census[censusSize];
census[0].animalType = dog;
census[0].name = "Fred";
census[0].stay = 13;
census[0].status[0] = Rabies;
census[0].status[1] = Bordetella;
census[0].status[2] = Parvovirus;
census[1].animalType = cat;
census[1].name = "Felix";
census[1].stay = 25;
census[1].status[0] = Rabies;
census[1].status[1] = Bordetella;
census[1].status[2] = Parvovirus;
census[2].animalType = dog;
census[2].name = "Fido";
census[2].stay = 18;
census[2].status[0] = Bordetella;
census[2].status[1] = Parvovirus;
census[2].status[2] = Leptospirosis;
census[3].animalType = cat;
census[3].name = "Garfield";
census[3].stay = 13;
census[3].status[0] = Rabies;
census[3].status[1] = Parvovirus;
census[4].animalType = rabbit;
census[4].name = "Peter";
census[4].stay = 18;
census[4].status[0] = Rabies;
census[4].status[1] = Parvovirus;
census[4].status[2] = Bordetella;
census[5].animalType = bird;
census[5].name = "Tweety";
census[5].stay = 25;
census[5].status[0] = Rabies;
census[5].status[1] = Bordetella;
census[5].status[2] = Parvovirus;
for (int m = 0; m < censusSize; m++)
displayAnimal(&census[m]);
double sum;
sum = 0;
for (int m = 0; m < censusSize; m++)
sum = averageStay(&census[m]);
cout << "The average stay is " << sum << " days." << endl;
int population[numberSpecies];
population[dog] = countPopulation(census, dog, censusSize);
population[cat] = countPopulation(census, cat, censusSize);
population[bird] = countPopulation(census, bird, censusSize);
population[rabbit] = countPopulation(census, rabbit, censusSize);
cout << "The number of dogs is " << population[dog] << "." << endl;
cout << "The number of cats is " << population[cat] << "." << endl;
cout << "The number of birds is " << population[bird] << "." << endl;
cout << "The number of rabbits is " << population[rabbit] << "." << endl;
cout << endl;
string temp;
for (int m = 0; m < censusSize; m++)
{
if (shotRecord(&census[m]))
{
temp = census[m].name;
cout << temp << " has all of his/her required shots." << endl;
}
}
cout << endl;
system("pause");
return 0;
}
Solution
#include
#include
#include
#include
using namespace std;
#define numberSpecies 4
#define numberShots 3
enum species {dog, cat, bird, rabbit};
enum shots {Parvovirus, Rabies, Bordetella, Leptospirosis};
string outString;
struct animal
{
string name;
unsigned int stay;
enum species animalType;
enum shots status[numberShots];
};
int displayAnimal(struct animal *animal)
{
cout << "Name:tt" << animal->name << endl;
cout << "Species:t";
switch (animal->animalType)
{
case dog:
cout << "Dog";
break;
case cat:
cout << "Cat";
break;
case bird:
cout << "Bird";
break;
case rabbit:
cout << "Rabbit";
break;
default:
cout << "Unknown";
}
cout << endl;
cout << "Length of stay: " << animal->stay << endl << endl;
return 0;
}
double averageStay(struct animal *animal)
{
return animal->stay;
}
int countPopulation(struct animal census[], enum species kindAnimal, unsigned int k)
{
unsigned int animalCount = 0;
for(int i = 0; i < k; i++)
{
if(census[i].animalType == kindAnimal)
animalCount++;
}
return animalCount;
}
bool shotRecord(struct animal *animal)
{
int countOfShots = 0;
for(int i = 0; i < numberShots; i++)
{
if(animal->status[i] == Parvovirus || animal->status[i] == Bordetella || animal->status[i] ==
Rabies)
countOfShots++;
}
return (countOfShots == 3) ? true: false;
}
int main()
{
#define censusSize 6
struct animal census[censusSize];
census[0].animalType = dog;
census[0].name = "Fred";
census[0].stay = 13;
census[0].status[0] = Rabies;
census[0].status[1] = Bordetella;
census[0].status[2] = Parvovirus;
census[1].animalType = cat;
census[1].name = "Felix";
census[1].stay = 25;
census[1].status[0] = Rabies;
census[1].status[1] = Bordetella;
census[1].status[2] = Parvovirus;
census[2].animalType = dog;
census[2].name = "Fido";
census[2].stay = 18;
census[2].status[0] = Bordetella;
census[2].status[1] = Parvovirus;
census[2].status[2] = Leptospirosis;
census[3].animalType = cat;
census[3].name = "Garfield";
census[3].stay = 13;
census[3].status[0] = Rabies;
census[3].status[1] = Parvovirus;
census[4].animalType = rabbit;
census[4].name = "Peter";
census[4].stay = 18;
census[4].status[0] = Rabies;
census[4].status[1] = Parvovirus;
census[4].status[2] = Bordetella;
census[5].animalType = bird;
census[5].name = "Tweety";
census[5].stay = 25;
census[5].status[0] = Rabies;
census[5].status[1] = Bordetella;
census[5].status[2] = Parvovirus;
for (int m = 0; m < censusSize; m++)
displayAnimal(&census[m]);
double sum;
sum = 0;
for (int m = 0; m < censusSize; m++)
sum += averageStay(&census[m]);
cout << "The average stay is " << sum/censusSize << " days." << endl;
int population[numberSpecies];
population[dog] = countPopulation(census, dog, censusSize);
population[cat] = countPopulation(census, cat, censusSize);
population[bird] = countPopulation(census, bird, censusSize);
population[rabbit] = countPopulation(census, rabbit, censusSize);
cout << "The number of dogs is " << population[dog] << "." << endl;
cout << "The number of cats is " << population[cat] << "." << endl;
cout << "The number of birds is " << population[bird] << "." << endl;
cout << "The number of rabbits is " << population[rabbit] << "." << endl;
cout << endl;
string temp;
for (int m = 0; m < censusSize; m++)
{
if (shotRecord(&census[m]))
{
temp = census[m].name;
cout << temp << " has all of his/her required shots." << endl;
}
}
cout << endl;
system("pause");
return 0;
}

More Related Content

Similar to All programming assignments should include the name, or names, of th.pdf

第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
anzhong70
 
The purpose of this project is to give students more exposure to obje.pdf
The purpose of this project is to give students more exposure to obje.pdfThe purpose of this project is to give students more exposure to obje.pdf
The purpose of this project is to give students more exposure to obje.pdf
forwardcom41
 
YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx
 YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx
YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx
gertrudebellgrove
 

Similar to All programming assignments should include the name, or names, of th.pdf (20)

第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
 
CSC PPT 13.pptx
CSC PPT 13.pptxCSC PPT 13.pptx
CSC PPT 13.pptx
 
Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Python basic
Python basicPython basic
Python basic
 
Chapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptxChapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptx
 
The purpose of this project is to give students more exposure to obje.pdf
The purpose of this project is to give students more exposure to obje.pdfThe purpose of this project is to give students more exposure to obje.pdf
The purpose of this project is to give students more exposure to obje.pdf
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
 
Trying to learn C# (NDC Oslo 2019)
Trying to learn C# (NDC Oslo 2019)Trying to learn C# (NDC Oslo 2019)
Trying to learn C# (NDC Oslo 2019)
 
Hw12 refactoring to factory method
Hw12 refactoring to factory methodHw12 refactoring to factory method
Hw12 refactoring to factory method
 
In this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdfIn this project you will define some interfaces, abstract classes, a.pdf
In this project you will define some interfaces, abstract classes, a.pdf
 
Python Basic
Python BasicPython Basic
Python Basic
 
Python slide
Python slidePython slide
Python slide
 
YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx
 YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx
YOU SHOULD NOT MODIFY ANYTHING IN THIS FILE .docx
 

More from fashioncollection2

Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdf
fashioncollection2
 
Why is “Profit” a problematic target Please consider in your answer.pdf
Why is “Profit” a problematic target Please consider in your answer.pdfWhy is “Profit” a problematic target Please consider in your answer.pdf
Why is “Profit” a problematic target Please consider in your answer.pdf
fashioncollection2
 
What is the role of abiotic factors in the formation of biomesS.pdf
What is the role of abiotic factors in the formation of biomesS.pdfWhat is the role of abiotic factors in the formation of biomesS.pdf
What is the role of abiotic factors in the formation of biomesS.pdf
fashioncollection2
 
What are the major terrestrial adaptations of plants1- List the F.pdf
What are the major terrestrial adaptations of plants1- List the F.pdfWhat are the major terrestrial adaptations of plants1- List the F.pdf
What are the major terrestrial adaptations of plants1- List the F.pdf
fashioncollection2
 
The insatiable demand for everything wireless, video, and Web-enable.pdf
The insatiable demand for everything wireless, video, and Web-enable.pdfThe insatiable demand for everything wireless, video, and Web-enable.pdf
The insatiable demand for everything wireless, video, and Web-enable.pdf
fashioncollection2
 
Technology is an ever-growing system that provides advantages and in.pdf
Technology is an ever-growing system that provides advantages and in.pdfTechnology is an ever-growing system that provides advantages and in.pdf
Technology is an ever-growing system that provides advantages and in.pdf
fashioncollection2
 
Role of involvement in consumer decision-making. Identify the level .pdf
Role of involvement in consumer decision-making. Identify the level .pdfRole of involvement in consumer decision-making. Identify the level .pdf
Role of involvement in consumer decision-making. Identify the level .pdf
fashioncollection2
 
Questionsa What are some of the barriers to understanding an issu.pdf
Questionsa What are some of the barriers to understanding an issu.pdfQuestionsa What are some of the barriers to understanding an issu.pdf
Questionsa What are some of the barriers to understanding an issu.pdf
fashioncollection2
 
Rainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdf
Rainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdfRainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdf
Rainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdf
fashioncollection2
 
Quality software project managementHow are tasks, activities, and .pdf
Quality software project managementHow are tasks, activities, and .pdfQuality software project managementHow are tasks, activities, and .pdf
Quality software project managementHow are tasks, activities, and .pdf
fashioncollection2
 

More from fashioncollection2 (20)

After a (not very successful) trick or treating round, Candice has 1.pdf
After a (not very successful) trick or treating round, Candice has 1.pdfAfter a (not very successful) trick or treating round, Candice has 1.pdf
After a (not very successful) trick or treating round, Candice has 1.pdf
 
Why steroids can cross the cell membraneWhy steroids can cross .pdf
Why steroids can cross the cell membraneWhy steroids can cross .pdfWhy steroids can cross the cell membraneWhy steroids can cross .pdf
Why steroids can cross the cell membraneWhy steroids can cross .pdf
 
Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdf
 
Write a command in unixlinux to Display all the files whose names e.pdf
Write a command in unixlinux to Display all the files whose names e.pdfWrite a command in unixlinux to Display all the files whose names e.pdf
Write a command in unixlinux to Display all the files whose names e.pdf
 
Why is “Profit” a problematic target Please consider in your answer.pdf
Why is “Profit” a problematic target Please consider in your answer.pdfWhy is “Profit” a problematic target Please consider in your answer.pdf
Why is “Profit” a problematic target Please consider in your answer.pdf
 
Which of the following statements about protists is falsea) There a.pdf
Which of the following statements about protists is falsea) There a.pdfWhich of the following statements about protists is falsea) There a.pdf
Which of the following statements about protists is falsea) There a.pdf
 
Which cable type would be used to connect a router to a switchA. .pdf
Which cable type would be used to connect a router to a switchA. .pdfWhich cable type would be used to connect a router to a switchA. .pdf
Which cable type would be used to connect a router to a switchA. .pdf
 
What is the role of abiotic factors in the formation of biomesS.pdf
What is the role of abiotic factors in the formation of biomesS.pdfWhat is the role of abiotic factors in the formation of biomesS.pdf
What is the role of abiotic factors in the formation of biomesS.pdf
 
What information needs to be encoded in a loadstorebranchALU inst.pdf
What information needs to be encoded in a loadstorebranchALU inst.pdfWhat information needs to be encoded in a loadstorebranchALU inst.pdf
What information needs to be encoded in a loadstorebranchALU inst.pdf
 
What are the major terrestrial adaptations of plants1- List the F.pdf
What are the major terrestrial adaptations of plants1- List the F.pdfWhat are the major terrestrial adaptations of plants1- List the F.pdf
What are the major terrestrial adaptations of plants1- List the F.pdf
 
The total lung capacity of a patient is 5.5 liters. Find the patient.pdf
The total lung capacity of a patient is 5.5 liters. Find the patient.pdfThe total lung capacity of a patient is 5.5 liters. Find the patient.pdf
The total lung capacity of a patient is 5.5 liters. Find the patient.pdf
 
The insatiable demand for everything wireless, video, and Web-enable.pdf
The insatiable demand for everything wireless, video, and Web-enable.pdfThe insatiable demand for everything wireless, video, and Web-enable.pdf
The insatiable demand for everything wireless, video, and Web-enable.pdf
 
Technology is an ever-growing system that provides advantages and in.pdf
Technology is an ever-growing system that provides advantages and in.pdfTechnology is an ever-growing system that provides advantages and in.pdf
Technology is an ever-growing system that provides advantages and in.pdf
 
Suppose that the proportions of blood phenotypes in a particular pop.pdf
Suppose that the proportions of blood phenotypes in a particular pop.pdfSuppose that the proportions of blood phenotypes in a particular pop.pdf
Suppose that the proportions of blood phenotypes in a particular pop.pdf
 
Select all of the following that are true regarding evolution. Altho.pdf
Select all of the following that are true regarding evolution.  Altho.pdfSelect all of the following that are true regarding evolution.  Altho.pdf
Select all of the following that are true regarding evolution. Altho.pdf
 
Role of involvement in consumer decision-making. Identify the level .pdf
Role of involvement in consumer decision-making. Identify the level .pdfRole of involvement in consumer decision-making. Identify the level .pdf
Role of involvement in consumer decision-making. Identify the level .pdf
 
Questionsa What are some of the barriers to understanding an issu.pdf
Questionsa What are some of the barriers to understanding an issu.pdfQuestionsa What are some of the barriers to understanding an issu.pdf
Questionsa What are some of the barriers to understanding an issu.pdf
 
Rainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdf
Rainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdfRainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdf
Rainfall Intensity Duration Frequency Graph ear Reture Period torm Du.pdf
 
Quality software project managementHow are tasks, activities, and .pdf
Quality software project managementHow are tasks, activities, and .pdfQuality software project managementHow are tasks, activities, and .pdf
Quality software project managementHow are tasks, activities, and .pdf
 
Part I Write the complete class definition (or server) for Unsorte.pdf
Part I Write the complete class definition (or server) for Unsorte.pdfPart I Write the complete class definition (or server) for Unsorte.pdf
Part I Write the complete class definition (or server) for Unsorte.pdf
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

All programming assignments should include the name, or names, of th.pdf

  • 1. All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The introductory comments should also contain the purpose of the program. Clear, concise, commenting is an important skill to develop and will be part of the grade for each program. Programs should be submitted via Blackboard as “.cpp” source programs. Each member of a team should submit a copy of the program. The purpose of PSA 7 is practice our programming style and techniques on a fairly simple real world example of an application. PSA7.cpp is a program that analyzes various aspects of the clients at an animal shelter. Your task is to fill in the three routines that provide the necessary information to the main routine. You may not alter the code in main. You must use the interfaces as defined. The first two routines are almost trivial and the only thing that is special about one of them is the need to use a persistent variable. The third one, shotRecord is a bit challenging. You must determine if each animal has had the correct shots. These are for Parvovirus, Rabies, and Bordetella. One confusion factor here is that they could have also received a shot for Leptospirosis; that is not a required shot. Further complicating things is the fact that the only thing that is important is that they received the shot; they may have received their inoculations in differing orders. Programme it using "CODE::BLOCK and also use the main function below: #include #include #include #include using namespace std; #define numberSpecies 4 #define numberShots 3 enum species {dog, cat, bird, rabbit}; enum shots {Parvovirus, Rabies, Bordetella, Leptospirosis}; string outString; struct animal {
  • 2. string name; unsigned int stay; enum species animalType; enum shots status[numberShots]; }; int displayAnimal(struct animal *animal) { cout << "Name:tt" << animal->name << endl; cout << "Species:t"; switch (animal->animalType) { case dog: cout << "Dog"; break; case cat: cout << "Cat"; break; case bird: cout << "Bird"; break; case rabbit: cout << "Rabbit"; break; default: cout << "Unknown"; } cout << endl; cout << "Length of stay: " << animal->stay << endl << endl; return 0; } double averageStay(struct animal *animal) { // Your code goes here. // Hint you will need to use a type we have not used before. } int countPopulation(struct animal census[], enum species kindAnimal, unsigned int k)
  • 3. { unsigned int j, animalCount; // Your code goes here. return animalCount; } bool shotRecord(struct animal *animal) { unsigned int temp, m, shot; temp = 0; // Your code goes here. // This is the trickiest one! return (temp == 3) ? true: false; } int main() { #define censusSize 6 struct animal census[censusSize]; census[0].animalType = dog; census[0].name = "Fred"; census[0].stay = 13; census[0].status[0] = Rabies; census[0].status[1] = Bordetella; census[0].status[2] = Parvovirus; census[1].animalType = cat; census[1].name = "Felix"; census[1].stay = 25; census[1].status[0] = Rabies; census[1].status[1] = Bordetella; census[1].status[2] = Parvovirus; census[2].animalType = dog; census[2].name = "Fido"; census[2].stay = 18; census[2].status[0] = Bordetella; census[2].status[1] = Parvovirus; census[2].status[2] = Leptospirosis; census[3].animalType = cat;
  • 4. census[3].name = "Garfield"; census[3].stay = 13; census[3].status[0] = Rabies; census[3].status[1] = Parvovirus; census[4].animalType = rabbit; census[4].name = "Peter"; census[4].stay = 18; census[4].status[0] = Rabies; census[4].status[1] = Parvovirus; census[4].status[2] = Bordetella; census[5].animalType = bird; census[5].name = "Tweety"; census[5].stay = 25; census[5].status[0] = Rabies; census[5].status[1] = Bordetella; census[5].status[2] = Parvovirus; for (int m = 0; m < censusSize; m++) displayAnimal(&census[m]); double sum; sum = 0; for (int m = 0; m < censusSize; m++) sum = averageStay(&census[m]); cout << "The average stay is " << sum << " days." << endl; int population[numberSpecies]; population[dog] = countPopulation(census, dog, censusSize); population[cat] = countPopulation(census, cat, censusSize); population[bird] = countPopulation(census, bird, censusSize); population[rabbit] = countPopulation(census, rabbit, censusSize); cout << "The number of dogs is " << population[dog] << "." << endl; cout << "The number of cats is " << population[cat] << "." << endl; cout << "The number of birds is " << population[bird] << "." << endl; cout << "The number of rabbits is " << population[rabbit] << "." << endl; cout << endl; string temp; for (int m = 0; m < censusSize; m++) {
  • 5. if (shotRecord(&census[m])) { temp = census[m].name; cout << temp << " has all of his/her required shots." << endl; } } cout << endl; system("pause"); return 0; } Solution #include #include #include #include using namespace std; #define numberSpecies 4 #define numberShots 3 enum species {dog, cat, bird, rabbit}; enum shots {Parvovirus, Rabies, Bordetella, Leptospirosis}; string outString; struct animal { string name; unsigned int stay; enum species animalType; enum shots status[numberShots]; }; int displayAnimal(struct animal *animal) { cout << "Name:tt" << animal->name << endl; cout << "Species:t"; switch (animal->animalType) {
  • 6. case dog: cout << "Dog"; break; case cat: cout << "Cat"; break; case bird: cout << "Bird"; break; case rabbit: cout << "Rabbit"; break; default: cout << "Unknown"; } cout << endl; cout << "Length of stay: " << animal->stay << endl << endl; return 0; } double averageStay(struct animal *animal) { return animal->stay; } int countPopulation(struct animal census[], enum species kindAnimal, unsigned int k) { unsigned int animalCount = 0; for(int i = 0; i < k; i++) { if(census[i].animalType == kindAnimal) animalCount++; } return animalCount; } bool shotRecord(struct animal *animal) { int countOfShots = 0;
  • 7. for(int i = 0; i < numberShots; i++) { if(animal->status[i] == Parvovirus || animal->status[i] == Bordetella || animal->status[i] == Rabies) countOfShots++; } return (countOfShots == 3) ? true: false; } int main() { #define censusSize 6 struct animal census[censusSize]; census[0].animalType = dog; census[0].name = "Fred"; census[0].stay = 13; census[0].status[0] = Rabies; census[0].status[1] = Bordetella; census[0].status[2] = Parvovirus; census[1].animalType = cat; census[1].name = "Felix"; census[1].stay = 25; census[1].status[0] = Rabies; census[1].status[1] = Bordetella; census[1].status[2] = Parvovirus; census[2].animalType = dog; census[2].name = "Fido"; census[2].stay = 18; census[2].status[0] = Bordetella; census[2].status[1] = Parvovirus; census[2].status[2] = Leptospirosis; census[3].animalType = cat; census[3].name = "Garfield"; census[3].stay = 13; census[3].status[0] = Rabies; census[3].status[1] = Parvovirus; census[4].animalType = rabbit;
  • 8. census[4].name = "Peter"; census[4].stay = 18; census[4].status[0] = Rabies; census[4].status[1] = Parvovirus; census[4].status[2] = Bordetella; census[5].animalType = bird; census[5].name = "Tweety"; census[5].stay = 25; census[5].status[0] = Rabies; census[5].status[1] = Bordetella; census[5].status[2] = Parvovirus; for (int m = 0; m < censusSize; m++) displayAnimal(&census[m]); double sum; sum = 0; for (int m = 0; m < censusSize; m++) sum += averageStay(&census[m]); cout << "The average stay is " << sum/censusSize << " days." << endl; int population[numberSpecies]; population[dog] = countPopulation(census, dog, censusSize); population[cat] = countPopulation(census, cat, censusSize); population[bird] = countPopulation(census, bird, censusSize); population[rabbit] = countPopulation(census, rabbit, censusSize); cout << "The number of dogs is " << population[dog] << "." << endl; cout << "The number of cats is " << population[cat] << "." << endl; cout << "The number of birds is " << population[bird] << "." << endl; cout << "The number of rabbits is " << population[rabbit] << "." << endl; cout << endl; string temp; for (int m = 0; m < censusSize; m++) { if (shotRecord(&census[m])) { temp = census[m].name; cout << temp << " has all of his/her required shots." << endl; }