SlideShare uma empresa Scribd logo
1 de 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.

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 

Último (20)

YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 

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.