SlideShare a Scribd company logo
1 of 9
CPSC 131 Homework 2
D e a d l i n e :D e a d l i n e : Wednesday, Feb-8
(MoWe sections)
Thursday, Feb-9 (TuTh sections)
Turn in your submission as hard copy in class.
#1 (will be graded for credit) consists of Part A
and Part B:
Pa r t A :Pa r t A : Consider the following class called
Myscores that stores all the scores for a
game.
class Myscores {
public:
Myscores() { //
constructor
nScores = 0;
}
void addScore(int
newscore) {
score[nScores] =
newscore;
nScores++;
}
CPSC 131 Homework 2
D e a d l i n e :D e a d l i n e : Wednesday, Feb-8
(MoWe sections)
Thursday, Feb-9 (TuTh sections)
Turn in your submission as hard copy in class.
#1 (will be graded for credit) consists of Part A
and Part B:
Pa r t A :Pa r t A : Consider the following class called
Myscores that stores all the scores for a
game.
class Myscores {
public:
Myscores() { //
constructor
nScores = 0;
}
void addScore(int
newscore) {
score[nScores] =
newscore;
nScores++;
}
Homework 2
Homework 2.pdf
Saved to Dropbox • Feb 2, 2017, 5<06 AM
https://docs.google.com/document/d/15hVUHOjAVxTJ_K1TOs
Txo3m1FGG-R30OzbPWxKOXWVk/mobilebasic
https://drive.google.com/?authuser=0&usp=docs_web
}
private:
int score[10];
int nScores; //
number of scores
stored
};
i) The score member variable
can store at most 10 scores. Change the
code so that score can store as many
scores as needed when a Myscores
object is created. (Hint: use dynamic
memory). Change/add constructor and
destructors as needed.
ii) Add a copy constructor for the
above case.
Pa r t BPa r t B: Create a template for class
GenericArray to print out the values in
arrays with data types: integer, float, or string.
Hints: Example of a class for integer data type
is shown below. Note that the below is not a
template class and your task is to convert it to a
template class that will work for integer, float
or string.
// this is only a partial example
class array for integer data type.
// You need to rewrite it as a
template class to support int,
float,
// and string data types.
class GenericArray {
public:
}
private:
int score[10];
int nScores; //
number of scores
stored
};
i) The score member variable
can store at most 10 scores. Change the
code so that score can store as many
scores as needed when a Myscores
object is created. (Hint: use dynamic
memory). Change/add constructor and
destructors as needed.
ii) Add a copy constructor for the
above case.
Pa r t BPa r t B: Create a template for class
GenericArray to print out the values in
arrays with data types: integer, float, or string.
Hints: Example of a class for integer data type
is shown below. Note that the below is not a
template class and your task is to convert it to a
template class that will work for integer, float
or string.
// this is only a partial example
class array for integer data type.
// You need to rewrite it as a
template class to support int,
float,
// and string data types.
class GenericArray {
public:
GenericArray(int array[],
int arraysize); // constructor
~GenericArray();
// destructor
void print();
// the print function
private:
int *ptr;
int size;
};
// This main function requires
the template class
GenericArray to work and it
can be used to test the
template class that you
created. Do not change.
int main() {
// using integer data
type
int arraya[5] = { 1, 2, 3,
4, 5 };
GenericArray<int>
a(arraya, 5);
a.print();
// using float data type
float arrayb[5] = {
1.012, 2.324, 3.141, 4.221, 5.327
};
GenericArray<float>
b(arrayb, 5);
b.print();
// using string data
type
string arrayc[] = {
"Ch1", "Ch2", "Ch3", "Ch4",
"Ch5" };
GenericArray<string>
c(arrayc, 5);
c.print();
return 0;
}
GenericArray(int array[],
int arraysize); // constructor
~GenericArray();
// destructor
void print();
// the print function
private:
int *ptr;
int size;
};
// This main function requires
the template class
GenericArray to work and it
can be used to test the
template class that you
created. Do not change.
int main() {
// using integer data
type
int arraya[5] = { 1, 2, 3,
4, 5 };
GenericArray<int>
a(arraya, 5);
a.print();
// using float data type
float arrayb[5] = {
1.012, 2.324, 3.141, 4.221, 5.327
};
GenericArray<float>
b(arrayb, 5);
b.print();
// using string data
type
string arrayc[] = {
"Ch1", "Ch2", "Ch3", "Ch4",
"Ch5" };
GenericArray<string>
c(arrayc, 5);
c.print();
return 0;
}
Write the complete code for the class
template showing the header files,
namespaces and:
i) Template declaration
ii) The Constructor
iii) The Destructor
iv) The print() function
v) Test your class template by
running the main() function above and
capture the console screen output.
Show the runtime screenshot.
Write the complete code for the class
template showing the header files,
namespaces and:
i) Template declaration
ii) The Constructor
iii) The Destructor
iv) The print() function
v) Test your class template by
running the main() function above and
capture the console screen output.
Show the runtime screenshot.

More Related Content

Similar to CPSC 131 Homework 2 D e a d l i n e D e a d l i n e .docx

Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referentialbabuk110
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answersdebarghyamukherjee60
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21chinthala Vijaya Kumar
 
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdfSuggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdfssuser58be4b1
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxDeepasCSE
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdfvishalateen
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersANUSUYA S
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdfEvanpZjSandersony
 
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdfUse Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdfashishgargjaipuri
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 

Similar to CPSC 131 Homework 2 D e a d l i n e D e a d l i n e .docx (20)

Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
Arrays
ArraysArrays
Arrays
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
 
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdfSuggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
 
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdfUse Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
 
Structures
StructuresStructures
Structures
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 

More from vanesaburnand

InstructionsYou are to create YOUR OWN example of each of t.docx
InstructionsYou are to create YOUR OWN example of each of t.docxInstructionsYou are to create YOUR OWN example of each of t.docx
InstructionsYou are to create YOUR OWN example of each of t.docxvanesaburnand
 
InstructionsYou are a research group from BSocialMarketing, LLC.docx
InstructionsYou are a research group from BSocialMarketing, LLC.docxInstructionsYou are a research group from BSocialMarketing, LLC.docx
InstructionsYou are a research group from BSocialMarketing, LLC.docxvanesaburnand
 
InstructionsYou are attending an international journalist event.docx
InstructionsYou are attending an international journalist event.docxInstructionsYou are attending an international journalist event.docx
InstructionsYou are attending an international journalist event.docxvanesaburnand
 
InstructionsWrite the Organizational section of your project pap.docx
InstructionsWrite the Organizational section of your project pap.docxInstructionsWrite the Organizational section of your project pap.docx
InstructionsWrite the Organizational section of your project pap.docxvanesaburnand
 
InstructionsWrite a two-page (double spaced, Times New Roman S.docx
InstructionsWrite a two-page (double spaced, Times New Roman S.docxInstructionsWrite a two-page (double spaced, Times New Roman S.docx
InstructionsWrite a two-page (double spaced, Times New Roman S.docxvanesaburnand
 
InstructionsWrite a thesis statement in response to the topi.docx
InstructionsWrite a thesis statement in response to the topi.docxInstructionsWrite a thesis statement in response to the topi.docx
InstructionsWrite a thesis statement in response to the topi.docxvanesaburnand
 
InstructionsWhat You will choose a current issue of social.docx
InstructionsWhat You will choose a current issue of social.docxInstructionsWhat You will choose a current issue of social.docx
InstructionsWhat You will choose a current issue of social.docxvanesaburnand
 
InstructionsWrite a paper about the International Monetary Syste.docx
InstructionsWrite a paper about the International Monetary Syste.docxInstructionsWrite a paper about the International Monetary Syste.docx
InstructionsWrite a paper about the International Monetary Syste.docxvanesaburnand
 
InstructionsWrite a comprehensive medical report on a disease we.docx
InstructionsWrite a comprehensive medical report on a disease we.docxInstructionsWrite a comprehensive medical report on a disease we.docx
InstructionsWrite a comprehensive medical report on a disease we.docxvanesaburnand
 
InstructionsWhether you believe” in evolution or not, why is it.docx
InstructionsWhether you believe” in evolution or not, why is it.docxInstructionsWhether you believe” in evolution or not, why is it.docx
InstructionsWhether you believe” in evolution or not, why is it.docxvanesaburnand
 
InstructionsWe have been looking at different psychological .docx
InstructionsWe have been looking at different psychological .docxInstructionsWe have been looking at different psychological .docx
InstructionsWe have been looking at different psychological .docxvanesaburnand
 
InstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docx
InstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docxInstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docx
InstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docxvanesaburnand
 
InstructionsThis written assignment requires the student to inve.docx
InstructionsThis written assignment requires the student to inve.docxInstructionsThis written assignment requires the student to inve.docx
InstructionsThis written assignment requires the student to inve.docxvanesaburnand
 
InstructionsThe Art Form Most Meaningful to MePick the form .docx
InstructionsThe Art Form Most Meaningful to MePick the form .docxInstructionsThe Art Form Most Meaningful to MePick the form .docx
InstructionsThe Art Form Most Meaningful to MePick the form .docxvanesaburnand
 
InstructionsThink of a specific topic and two specific kin.docx
InstructionsThink of a specific topic and two specific kin.docxInstructionsThink of a specific topic and two specific kin.docx
InstructionsThink of a specific topic and two specific kin.docxvanesaburnand
 
InstructionsThere are different approaches to gathering risk da.docx
InstructionsThere are different approaches to gathering risk da.docxInstructionsThere are different approaches to gathering risk da.docx
InstructionsThere are different approaches to gathering risk da.docxvanesaburnand
 
InstructionsThe  Public Archaeology Presentation invites you.docx
InstructionsThe  Public Archaeology Presentation invites you.docxInstructionsThe  Public Archaeology Presentation invites you.docx
InstructionsThe  Public Archaeology Presentation invites you.docxvanesaburnand
 
InstructionsThe tools of formal analysis are the starting point .docx
InstructionsThe tools of formal analysis are the starting point .docxInstructionsThe tools of formal analysis are the starting point .docx
InstructionsThe tools of formal analysis are the starting point .docxvanesaburnand
 
InstructionsThe Homeland Security (DHS) agency is intended t.docx
InstructionsThe Homeland Security (DHS) agency is intended t.docxInstructionsThe Homeland Security (DHS) agency is intended t.docx
InstructionsThe Homeland Security (DHS) agency is intended t.docxvanesaburnand
 
InstructionsThe student should describe how learning abou.docx
InstructionsThe student should describe how learning abou.docxInstructionsThe student should describe how learning abou.docx
InstructionsThe student should describe how learning abou.docxvanesaburnand
 

More from vanesaburnand (20)

InstructionsYou are to create YOUR OWN example of each of t.docx
InstructionsYou are to create YOUR OWN example of each of t.docxInstructionsYou are to create YOUR OWN example of each of t.docx
InstructionsYou are to create YOUR OWN example of each of t.docx
 
InstructionsYou are a research group from BSocialMarketing, LLC.docx
InstructionsYou are a research group from BSocialMarketing, LLC.docxInstructionsYou are a research group from BSocialMarketing, LLC.docx
InstructionsYou are a research group from BSocialMarketing, LLC.docx
 
InstructionsYou are attending an international journalist event.docx
InstructionsYou are attending an international journalist event.docxInstructionsYou are attending an international journalist event.docx
InstructionsYou are attending an international journalist event.docx
 
InstructionsWrite the Organizational section of your project pap.docx
InstructionsWrite the Organizational section of your project pap.docxInstructionsWrite the Organizational section of your project pap.docx
InstructionsWrite the Organizational section of your project pap.docx
 
InstructionsWrite a two-page (double spaced, Times New Roman S.docx
InstructionsWrite a two-page (double spaced, Times New Roman S.docxInstructionsWrite a two-page (double spaced, Times New Roman S.docx
InstructionsWrite a two-page (double spaced, Times New Roman S.docx
 
InstructionsWrite a thesis statement in response to the topi.docx
InstructionsWrite a thesis statement in response to the topi.docxInstructionsWrite a thesis statement in response to the topi.docx
InstructionsWrite a thesis statement in response to the topi.docx
 
InstructionsWhat You will choose a current issue of social.docx
InstructionsWhat You will choose a current issue of social.docxInstructionsWhat You will choose a current issue of social.docx
InstructionsWhat You will choose a current issue of social.docx
 
InstructionsWrite a paper about the International Monetary Syste.docx
InstructionsWrite a paper about the International Monetary Syste.docxInstructionsWrite a paper about the International Monetary Syste.docx
InstructionsWrite a paper about the International Monetary Syste.docx
 
InstructionsWrite a comprehensive medical report on a disease we.docx
InstructionsWrite a comprehensive medical report on a disease we.docxInstructionsWrite a comprehensive medical report on a disease we.docx
InstructionsWrite a comprehensive medical report on a disease we.docx
 
InstructionsWhether you believe” in evolution or not, why is it.docx
InstructionsWhether you believe” in evolution or not, why is it.docxInstructionsWhether you believe” in evolution or not, why is it.docx
InstructionsWhether you believe” in evolution or not, why is it.docx
 
InstructionsWe have been looking at different psychological .docx
InstructionsWe have been looking at different psychological .docxInstructionsWe have been looking at different psychological .docx
InstructionsWe have been looking at different psychological .docx
 
InstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docx
InstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docxInstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docx
InstructionsTITLEF14-2Beginning an 8-column work sheet for a merch.docx
 
InstructionsThis written assignment requires the student to inve.docx
InstructionsThis written assignment requires the student to inve.docxInstructionsThis written assignment requires the student to inve.docx
InstructionsThis written assignment requires the student to inve.docx
 
InstructionsThe Art Form Most Meaningful to MePick the form .docx
InstructionsThe Art Form Most Meaningful to MePick the form .docxInstructionsThe Art Form Most Meaningful to MePick the form .docx
InstructionsThe Art Form Most Meaningful to MePick the form .docx
 
InstructionsThink of a specific topic and two specific kin.docx
InstructionsThink of a specific topic and two specific kin.docxInstructionsThink of a specific topic and two specific kin.docx
InstructionsThink of a specific topic and two specific kin.docx
 
InstructionsThere are different approaches to gathering risk da.docx
InstructionsThere are different approaches to gathering risk da.docxInstructionsThere are different approaches to gathering risk da.docx
InstructionsThere are different approaches to gathering risk da.docx
 
InstructionsThe  Public Archaeology Presentation invites you.docx
InstructionsThe  Public Archaeology Presentation invites you.docxInstructionsThe  Public Archaeology Presentation invites you.docx
InstructionsThe  Public Archaeology Presentation invites you.docx
 
InstructionsThe tools of formal analysis are the starting point .docx
InstructionsThe tools of formal analysis are the starting point .docxInstructionsThe tools of formal analysis are the starting point .docx
InstructionsThe tools of formal analysis are the starting point .docx
 
InstructionsThe Homeland Security (DHS) agency is intended t.docx
InstructionsThe Homeland Security (DHS) agency is intended t.docxInstructionsThe Homeland Security (DHS) agency is intended t.docx
InstructionsThe Homeland Security (DHS) agency is intended t.docx
 
InstructionsThe student should describe how learning abou.docx
InstructionsThe student should describe how learning abou.docxInstructionsThe student should describe how learning abou.docx
InstructionsThe student should describe how learning abou.docx
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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.pdfQucHHunhnh
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

CPSC 131 Homework 2 D e a d l i n e D e a d l i n e .docx

  • 1. CPSC 131 Homework 2 D e a d l i n e :D e a d l i n e : Wednesday, Feb-8 (MoWe sections) Thursday, Feb-9 (TuTh sections) Turn in your submission as hard copy in class. #1 (will be graded for credit) consists of Part A and Part B: Pa r t A :Pa r t A : Consider the following class called Myscores that stores all the scores for a game. class Myscores { public: Myscores() { // constructor nScores = 0; } void addScore(int newscore) { score[nScores] = newscore; nScores++;
  • 2. } CPSC 131 Homework 2 D e a d l i n e :D e a d l i n e : Wednesday, Feb-8 (MoWe sections) Thursday, Feb-9 (TuTh sections) Turn in your submission as hard copy in class. #1 (will be graded for credit) consists of Part A and Part B: Pa r t A :Pa r t A : Consider the following class called Myscores that stores all the scores for a game. class Myscores { public: Myscores() { // constructor nScores = 0; } void addScore(int newscore) { score[nScores] = newscore; nScores++; }
  • 3. Homework 2 Homework 2.pdf Saved to Dropbox • Feb 2, 2017, 5<06 AM https://docs.google.com/document/d/15hVUHOjAVxTJ_K1TOs Txo3m1FGG-R30OzbPWxKOXWVk/mobilebasic https://drive.google.com/?authuser=0&usp=docs_web } private: int score[10]; int nScores; // number of scores stored }; i) The score member variable can store at most 10 scores. Change the code so that score can store as many scores as needed when a Myscores object is created. (Hint: use dynamic memory). Change/add constructor and destructors as needed. ii) Add a copy constructor for the above case. Pa r t BPa r t B: Create a template for class GenericArray to print out the values in arrays with data types: integer, float, or string. Hints: Example of a class for integer data type
  • 4. is shown below. Note that the below is not a template class and your task is to convert it to a template class that will work for integer, float or string. // this is only a partial example class array for integer data type. // You need to rewrite it as a template class to support int, float, // and string data types. class GenericArray { public: } private: int score[10]; int nScores; // number of scores stored }; i) The score member variable can store at most 10 scores. Change the code so that score can store as many scores as needed when a Myscores object is created. (Hint: use dynamic memory). Change/add constructor and destructors as needed. ii) Add a copy constructor for the above case.
  • 5. Pa r t BPa r t B: Create a template for class GenericArray to print out the values in arrays with data types: integer, float, or string. Hints: Example of a class for integer data type is shown below. Note that the below is not a template class and your task is to convert it to a template class that will work for integer, float or string. // this is only a partial example class array for integer data type. // You need to rewrite it as a template class to support int, float, // and string data types. class GenericArray { public: GenericArray(int array[], int arraysize); // constructor ~GenericArray(); // destructor void print(); // the print function private: int *ptr; int size; };
  • 6. // This main function requires the template class GenericArray to work and it can be used to test the template class that you created. Do not change. int main() { // using integer data type int arraya[5] = { 1, 2, 3, 4, 5 }; GenericArray<int> a(arraya, 5); a.print(); // using float data type float arrayb[5] = { 1.012, 2.324, 3.141, 4.221, 5.327 }; GenericArray<float> b(arrayb, 5); b.print(); // using string data type string arrayc[] = { "Ch1", "Ch2", "Ch3", "Ch4", "Ch5" }; GenericArray<string> c(arrayc, 5); c.print(); return 0; }
  • 7. GenericArray(int array[], int arraysize); // constructor ~GenericArray(); // destructor void print(); // the print function private: int *ptr; int size; }; // This main function requires the template class GenericArray to work and it can be used to test the template class that you created. Do not change. int main() { // using integer data type int arraya[5] = { 1, 2, 3, 4, 5 }; GenericArray<int> a(arraya, 5); a.print(); // using float data type float arrayb[5] = { 1.012, 2.324, 3.141, 4.221, 5.327 }; GenericArray<float> b(arrayb, 5); b.print(); // using string data
  • 8. type string arrayc[] = { "Ch1", "Ch2", "Ch3", "Ch4", "Ch5" }; GenericArray<string> c(arrayc, 5); c.print(); return 0; } Write the complete code for the class template showing the header files, namespaces and: i) Template declaration ii) The Constructor iii) The Destructor iv) The print() function v) Test your class template by running the main() function above and capture the console screen output. Show the runtime screenshot. Write the complete code for the class template showing the header files, namespaces and: i) Template declaration ii) The Constructor
  • 9. iii) The Destructor iv) The print() function v) Test your class template by running the main() function above and capture the console screen output. Show the runtime screenshot.