SlideShare a Scribd company logo
1 of 8
Download to read offline
Note: Modified code
code:
#include
#include
#include
#include
#include
using namespace std;
#pragma warning(disable: 4996)
typedef enum { male = 0, female = 1 } gender; // enumeration type gender
struct dog {
char name[30];
gender genderValue;
char breed[30];
int age;
float weight;
};
int count = 0; // the amount of dogs currently stored in the list (initialized at 0)
struct dog list[30]; // initialize list of dogs
// forward declaration of functions
void flush();
void branching(char);
void helper(char);
int add(char*, char*, char*, int, float, struct dog*); // 30 points
char* search(char*, int, struct dog*); // 10 points
void display();
void save(char* fileName);
void load(char* fileName); // 10 points
int main()
{
load("Dog_List.txt"); // load list of dogs from file (if it exists)
char ch = 'i';
printf("Assignment 5: Array of Structs and Enum Types  ");
printf("Dog Adoption Center  ");
do
{
printf("Please enter your selection: ");
printf("ta: add a new dog to the list ");
printf("ts: search for a dog on the list ");
printf("td: display list of dogs ");
printf("tq: quit and save your list ");
ch = tolower(getchar());
flush();
branching(ch);
} while (ch != 'q');
save("Dog_List.txt"); // save list of dogs to file (overwrite if it exists)
return 0;
}
// consume leftover ' ' characters
void flush()
{
int c;
do c = getchar(); while (c != ' ' && c != EOF);
}
// branch to different tasks
void branching(char c)
{
switch (c)
{
case 'a':
case 's': helper(c); break;
case 'd': display(); break;
case 'q': break;
default: printf("Invalid input! ");
}
}
// The helper function is used to determine how much information is needed and which function
to send that information to.
// It uses values that are returned from some functions to produce the correct ouput.
// There is no implementation needed here, but you should study this function and know how it
works.
// It is always helpful to understand how the code works before implementing new features.
// Do not change anything in this function or you risk failing the automated test cases.
void helper(char c)
{
char input[100];
if (c == 'a')
{
printf(" Please enter the dog's information in the following format: ");
printf("tname:gender:breed:age:weight ");
fgets(input, sizeof(input), stdin);
// discard ' ' chars attached to input
input[strlen(input) - 1] = '0';
char* name = strtok(input, ":"); // strtok used to parse string
char* genderValueString = strtok(NULL, ":");
char* breed = strtok(NULL, ":");
int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int
float weight = atof(strtok(NULL, ":")); // atof used to convert string to float
int result = add(name, genderValueString, breed, age, weight, list);
if (result == 0)
printf(" That dog is already on the list  ");
else
printf(" Dog added to list successfully  ");
}
else // c = 's'
{
printf(" Please enter the dog's information in the following format: ");
printf("tname:age ");
fgets(input, sizeof(input), stdin);
char* name = strtok(input, ":"); // strtok used to parse string
int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int
char* result = search(name, age, list);
if (result == NULL)
printf(" That dog is not on the list  ");
else
printf(" Breed: %s  ", result);
}
}
// Q1 : add (30 points)
// This function is used to insert a new dog into the list.
// Your list should be sorted alphabetically by name, so you need to search for the correct index
to add into your list.
// If a dog already exists with the same name, then those dogs should be sorted by age.
// Do not allow for the same dog to be added to the list multiple times. (same name and same
age).
// If the dog already exists on the list, return 0. If the dog is added to the list, return 1.
//
// NOTE: You must convert the string "genderValueString to an enum type and store it in the
list. This will be tested.
// (You must store all of the required information correctly to pass all of the test cases)
// NOTE: You should not allow for the same dog to be added twice, you will lose points if you
do not account for this.
// (That means that dogs on the list are allowed to have the same name OR the same age, but not
both).
//
// You are not required to use pointer operations for your list but you may do so if you'd like.
// 'list' is passed to this function for automated testing purposes only, it is global.
int add(char* name, char* genderValueString, char* breed, int age, float weight, struct dog* list)
{
struct dog* temp;
gender gen;
char* test="M";
int i;
if(count>0)
{
for(i=0;i
Solution
Note: Modified code
code:
#include
#include
#include
#include
#include
using namespace std;
#pragma warning(disable: 4996)
typedef enum { male = 0, female = 1 } gender; // enumeration type gender
struct dog {
char name[30];
gender genderValue;
char breed[30];
int age;
float weight;
};
int count = 0; // the amount of dogs currently stored in the list (initialized at 0)
struct dog list[30]; // initialize list of dogs
// forward declaration of functions
void flush();
void branching(char);
void helper(char);
int add(char*, char*, char*, int, float, struct dog*); // 30 points
char* search(char*, int, struct dog*); // 10 points
void display();
void save(char* fileName);
void load(char* fileName); // 10 points
int main()
{
load("Dog_List.txt"); // load list of dogs from file (if it exists)
char ch = 'i';
printf("Assignment 5: Array of Structs and Enum Types  ");
printf("Dog Adoption Center  ");
do
{
printf("Please enter your selection: ");
printf("ta: add a new dog to the list ");
printf("ts: search for a dog on the list ");
printf("td: display list of dogs ");
printf("tq: quit and save your list ");
ch = tolower(getchar());
flush();
branching(ch);
} while (ch != 'q');
save("Dog_List.txt"); // save list of dogs to file (overwrite if it exists)
return 0;
}
// consume leftover ' ' characters
void flush()
{
int c;
do c = getchar(); while (c != ' ' && c != EOF);
}
// branch to different tasks
void branching(char c)
{
switch (c)
{
case 'a':
case 's': helper(c); break;
case 'd': display(); break;
case 'q': break;
default: printf("Invalid input! ");
}
}
// The helper function is used to determine how much information is needed and which function
to send that information to.
// It uses values that are returned from some functions to produce the correct ouput.
// There is no implementation needed here, but you should study this function and know how it
works.
// It is always helpful to understand how the code works before implementing new features.
// Do not change anything in this function or you risk failing the automated test cases.
void helper(char c)
{
char input[100];
if (c == 'a')
{
printf(" Please enter the dog's information in the following format: ");
printf("tname:gender:breed:age:weight ");
fgets(input, sizeof(input), stdin);
// discard ' ' chars attached to input
input[strlen(input) - 1] = '0';
char* name = strtok(input, ":"); // strtok used to parse string
char* genderValueString = strtok(NULL, ":");
char* breed = strtok(NULL, ":");
int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int
float weight = atof(strtok(NULL, ":")); // atof used to convert string to float
int result = add(name, genderValueString, breed, age, weight, list);
if (result == 0)
printf(" That dog is already on the list  ");
else
printf(" Dog added to list successfully  ");
}
else // c = 's'
{
printf(" Please enter the dog's information in the following format: ");
printf("tname:age ");
fgets(input, sizeof(input), stdin);
char* name = strtok(input, ":"); // strtok used to parse string
int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int
char* result = search(name, age, list);
if (result == NULL)
printf(" That dog is not on the list  ");
else
printf(" Breed: %s  ", result);
}
}
// Q1 : add (30 points)
// This function is used to insert a new dog into the list.
// Your list should be sorted alphabetically by name, so you need to search for the correct index
to add into your list.
// If a dog already exists with the same name, then those dogs should be sorted by age.
// Do not allow for the same dog to be added to the list multiple times. (same name and same
age).
// If the dog already exists on the list, return 0. If the dog is added to the list, return 1.
//
// NOTE: You must convert the string "genderValueString to an enum type and store it in the
list. This will be tested.
// (You must store all of the required information correctly to pass all of the test cases)
// NOTE: You should not allow for the same dog to be added twice, you will lose points if you
do not account for this.
// (That means that dogs on the list are allowed to have the same name OR the same age, but not
both).
//
// You are not required to use pointer operations for your list but you may do so if you'd like.
// 'list' is passed to this function for automated testing purposes only, it is global.
int add(char* name, char* genderValueString, char* breed, int age, float weight, struct dog* list)
{
struct dog* temp;
gender gen;
char* test="M";
int i;
if(count>0)
{
for(i=0;i

More Related Content

Similar to Note Modified codecode#includeiostream #include stdio.h.pdf

Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdf
info382133
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
arpaqindia
 
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
txkev
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
MAYANKBANSAL1981
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
sravi07
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
sravi07
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
karianneberg
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
sravi07
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
calderoncasto9163
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
Ian5L3Allanm
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
ganisyedtrd
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
fantasiatheoutofthef
 
My Program below this is supposed to do the following below here but.pdf
My Program below this is supposed to do the following below here but.pdfMy Program below this is supposed to do the following below here but.pdf
My Program below this is supposed to do the following below here but.pdf
arihantelehyb
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 

Similar to Note Modified codecode#includeiostream #include stdio.h.pdf (20)

Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdf
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
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
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
My Program below this is supposed to do the following below here but.pdf
My Program below this is supposed to do the following below here but.pdfMy Program below this is supposed to do the following below here but.pdf
My Program below this is supposed to do the following below here but.pdf
 
#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
 

More from sharnapiyush773

“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf
sharnapiyush773
 
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdfThe Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
sharnapiyush773
 
The main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdfThe main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdf
sharnapiyush773
 
The expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdfThe expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdf
sharnapiyush773
 
public class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdfpublic class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdf
sharnapiyush773
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
sharnapiyush773
 
OSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdfOSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdf
sharnapiyush773
 
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdfOligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
sharnapiyush773
 
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdfMaroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
sharnapiyush773
 
In developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdfIn developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdf
sharnapiyush773
 
Bryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdfBryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdf
sharnapiyush773
 
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdfEthernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
sharnapiyush773
 

More from sharnapiyush773 (20)

“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf
 
Trueas each officer has fixed paroleelesratio = no of parollesn.pdf
Trueas each officer has fixed paroleelesratio = no of parollesn.pdfTrueas each officer has fixed paroleelesratio = no of parollesn.pdf
Trueas each officer has fixed paroleelesratio = no of parollesn.pdf
 
to upperSolutionto upper.pdf
to upperSolutionto upper.pdfto upperSolutionto upper.pdf
to upperSolutionto upper.pdf
 
there are several theory on defining acid and base, Lewis acids and .pdf
there are several theory on defining acid and base, Lewis acids and .pdfthere are several theory on defining acid and base, Lewis acids and .pdf
there are several theory on defining acid and base, Lewis acids and .pdf
 
The Statement is False. As there are many applications of hyperbo;ic.pdf
The Statement is False. As there are many applications of hyperbo;ic.pdfThe Statement is False. As there are many applications of hyperbo;ic.pdf
The Statement is False. As there are many applications of hyperbo;ic.pdf
 
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdfThe Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
 
The main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdfThe main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdf
 
The expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdfThe expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdf
 
public class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdfpublic class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdf
 
picture is missingSolutionpicture is missing.pdf
picture is missingSolutionpicture is missing.pdfpicture is missingSolutionpicture is missing.pdf
picture is missingSolutionpicture is missing.pdf
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
 
OSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdfOSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdf
 
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdfOligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
 
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdfn = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
 
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdfMaroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
 
It lacks the origin of replication which is most important for the i.pdf
It lacks the origin of replication which is most important for the i.pdfIt lacks the origin of replication which is most important for the i.pdf
It lacks the origin of replication which is most important for the i.pdf
 
In developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdfIn developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdf
 
Bryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdfBryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdf
 
givenSolutiongiven.pdf
givenSolutiongiven.pdfgivenSolutiongiven.pdf
givenSolutiongiven.pdf
 
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdfEthernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
Ethernet II framing (also known as DIX Ethernet, named after DEC, In.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 

Recently uploaded (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 

Note Modified codecode#includeiostream #include stdio.h.pdf

  • 1. Note: Modified code code: #include #include #include #include #include using namespace std; #pragma warning(disable: 4996) typedef enum { male = 0, female = 1 } gender; // enumeration type gender struct dog { char name[30]; gender genderValue; char breed[30]; int age; float weight; }; int count = 0; // the amount of dogs currently stored in the list (initialized at 0) struct dog list[30]; // initialize list of dogs // forward declaration of functions void flush(); void branching(char); void helper(char); int add(char*, char*, char*, int, float, struct dog*); // 30 points char* search(char*, int, struct dog*); // 10 points void display(); void save(char* fileName); void load(char* fileName); // 10 points int main() { load("Dog_List.txt"); // load list of dogs from file (if it exists) char ch = 'i'; printf("Assignment 5: Array of Structs and Enum Types "); printf("Dog Adoption Center "); do
  • 2. { printf("Please enter your selection: "); printf("ta: add a new dog to the list "); printf("ts: search for a dog on the list "); printf("td: display list of dogs "); printf("tq: quit and save your list "); ch = tolower(getchar()); flush(); branching(ch); } while (ch != 'q'); save("Dog_List.txt"); // save list of dogs to file (overwrite if it exists) return 0; } // consume leftover ' ' characters void flush() { int c; do c = getchar(); while (c != ' ' && c != EOF); } // branch to different tasks void branching(char c) { switch (c) { case 'a': case 's': helper(c); break; case 'd': display(); break; case 'q': break; default: printf("Invalid input! "); } } // The helper function is used to determine how much information is needed and which function to send that information to. // It uses values that are returned from some functions to produce the correct ouput. // There is no implementation needed here, but you should study this function and know how it works.
  • 3. // It is always helpful to understand how the code works before implementing new features. // Do not change anything in this function or you risk failing the automated test cases. void helper(char c) { char input[100]; if (c == 'a') { printf(" Please enter the dog's information in the following format: "); printf("tname:gender:breed:age:weight "); fgets(input, sizeof(input), stdin); // discard ' ' chars attached to input input[strlen(input) - 1] = '0'; char* name = strtok(input, ":"); // strtok used to parse string char* genderValueString = strtok(NULL, ":"); char* breed = strtok(NULL, ":"); int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int float weight = atof(strtok(NULL, ":")); // atof used to convert string to float int result = add(name, genderValueString, breed, age, weight, list); if (result == 0) printf(" That dog is already on the list "); else printf(" Dog added to list successfully "); } else // c = 's' { printf(" Please enter the dog's information in the following format: "); printf("tname:age "); fgets(input, sizeof(input), stdin); char* name = strtok(input, ":"); // strtok used to parse string int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int char* result = search(name, age, list); if (result == NULL) printf(" That dog is not on the list "); else printf(" Breed: %s ", result); }
  • 4. } // Q1 : add (30 points) // This function is used to insert a new dog into the list. // Your list should be sorted alphabetically by name, so you need to search for the correct index to add into your list. // If a dog already exists with the same name, then those dogs should be sorted by age. // Do not allow for the same dog to be added to the list multiple times. (same name and same age). // If the dog already exists on the list, return 0. If the dog is added to the list, return 1. // // NOTE: You must convert the string "genderValueString to an enum type and store it in the list. This will be tested. // (You must store all of the required information correctly to pass all of the test cases) // NOTE: You should not allow for the same dog to be added twice, you will lose points if you do not account for this. // (That means that dogs on the list are allowed to have the same name OR the same age, but not both). // // You are not required to use pointer operations for your list but you may do so if you'd like. // 'list' is passed to this function for automated testing purposes only, it is global. int add(char* name, char* genderValueString, char* breed, int age, float weight, struct dog* list) { struct dog* temp; gender gen; char* test="M"; int i; if(count>0) { for(i=0;i Solution Note: Modified code code: #include #include #include
  • 5. #include #include using namespace std; #pragma warning(disable: 4996) typedef enum { male = 0, female = 1 } gender; // enumeration type gender struct dog { char name[30]; gender genderValue; char breed[30]; int age; float weight; }; int count = 0; // the amount of dogs currently stored in the list (initialized at 0) struct dog list[30]; // initialize list of dogs // forward declaration of functions void flush(); void branching(char); void helper(char); int add(char*, char*, char*, int, float, struct dog*); // 30 points char* search(char*, int, struct dog*); // 10 points void display(); void save(char* fileName); void load(char* fileName); // 10 points int main() { load("Dog_List.txt"); // load list of dogs from file (if it exists) char ch = 'i'; printf("Assignment 5: Array of Structs and Enum Types "); printf("Dog Adoption Center "); do { printf("Please enter your selection: "); printf("ta: add a new dog to the list "); printf("ts: search for a dog on the list "); printf("td: display list of dogs "); printf("tq: quit and save your list ");
  • 6. ch = tolower(getchar()); flush(); branching(ch); } while (ch != 'q'); save("Dog_List.txt"); // save list of dogs to file (overwrite if it exists) return 0; } // consume leftover ' ' characters void flush() { int c; do c = getchar(); while (c != ' ' && c != EOF); } // branch to different tasks void branching(char c) { switch (c) { case 'a': case 's': helper(c); break; case 'd': display(); break; case 'q': break; default: printf("Invalid input! "); } } // The helper function is used to determine how much information is needed and which function to send that information to. // It uses values that are returned from some functions to produce the correct ouput. // There is no implementation needed here, but you should study this function and know how it works. // It is always helpful to understand how the code works before implementing new features. // Do not change anything in this function or you risk failing the automated test cases. void helper(char c) { char input[100]; if (c == 'a')
  • 7. { printf(" Please enter the dog's information in the following format: "); printf("tname:gender:breed:age:weight "); fgets(input, sizeof(input), stdin); // discard ' ' chars attached to input input[strlen(input) - 1] = '0'; char* name = strtok(input, ":"); // strtok used to parse string char* genderValueString = strtok(NULL, ":"); char* breed = strtok(NULL, ":"); int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int float weight = atof(strtok(NULL, ":")); // atof used to convert string to float int result = add(name, genderValueString, breed, age, weight, list); if (result == 0) printf(" That dog is already on the list "); else printf(" Dog added to list successfully "); } else // c = 's' { printf(" Please enter the dog's information in the following format: "); printf("tname:age "); fgets(input, sizeof(input), stdin); char* name = strtok(input, ":"); // strtok used to parse string int age = atoi(strtok(NULL, ":")); // atoi used to convert string to int char* result = search(name, age, list); if (result == NULL) printf(" That dog is not on the list "); else printf(" Breed: %s ", result); } } // Q1 : add (30 points) // This function is used to insert a new dog into the list. // Your list should be sorted alphabetically by name, so you need to search for the correct index to add into your list. // If a dog already exists with the same name, then those dogs should be sorted by age.
  • 8. // Do not allow for the same dog to be added to the list multiple times. (same name and same age). // If the dog already exists on the list, return 0. If the dog is added to the list, return 1. // // NOTE: You must convert the string "genderValueString to an enum type and store it in the list. This will be tested. // (You must store all of the required information correctly to pass all of the test cases) // NOTE: You should not allow for the same dog to be added twice, you will lose points if you do not account for this. // (That means that dogs on the list are allowed to have the same name OR the same age, but not both). // // You are not required to use pointer operations for your list but you may do so if you'd like. // 'list' is passed to this function for automated testing purposes only, it is global. int add(char* name, char* genderValueString, char* breed, int age, float weight, struct dog* list) { struct dog* temp; gender gen; char* test="M"; int i; if(count>0) { for(i=0;i