SlideShare una empresa de Scribd logo
1 de 3
COMP/220 iLab 5 of 7 - C++ Course

iLab 5 of 7: Pointers and Pointer Operations

iLAB OVERVIEW

Scenario and Summary

This lab will explore the use of pointers in several ways. Pointers will be used to dynamically allocate
memory for new class objects on demand from the user, and they will be used to access class-
member functions. Pointer arithmetic will be used to access and sort class objects according to
criteria explained in the lab.

Pointers are, essentially, address variables, or variables that hold as their value the address of other
variables. In terms of memory management, they are very powerful devices, and they more closely
and efficiently use the actual internal hardware registers of the microprocessor that the program
operates on.

Pointers also have the requirement that the pointer type must be of the same data type as the
variable, or the data that it points to or holds the address of. The power of pointers also hints at the
potential complexity of their use, which is why this lab is focused almost entirely on several different
aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers.

The Resistor class created in the Week 2 lab will be used as the class that the pointer operations will
be used upon. The lab also requires the use of accessor functions and static data members, which
may need to be added to the Resistor class definition and implementation.

Deliverables

1.         Submit a single Notepad file containing the source code for all the files of the lab to the
Dropbox for Week 5. Your source code should use proper indentation and be error free. Be sure that
your last name and the lab number are part of the file name: for example, YourLastName_Lab5.txt.



Each program should include a comment section that includes, at a minimum, your name, the lab
and exercise number, and a description of what the program accomplishes.

2.       Submit a lab report (a Word document) containing the following information to the
Dropbox for Week 5.

o         Include your name and the lab or lab-exercise number.

o          Specification: Include a brief description of what the program accomplishes, including its
input, key processes, and output.

o          Test Plan: Include a brief description of the method you used to confirm that your
program worked properly. If necessary, include a clearly labeled table with test cases, predicted
results, and actual results.
o         Summary and Conclusions: Write a statement summarizing your predicted and actual
output, and identify and explain any differences. For conclusions, write at least one nontrivial
paragraph that explains, in detail, either a significant problem you had and how you solved it or, if
you had no significant problems, something you learned by doing the exercise.

o         A UML diagram: This should show all classes, class members, access specifiers, data
types, and function arguments, along with any and all class-to-class relationships.

o         Answers to Lab Questions: Answer any and all lab questions included in the lab steps.

Each lab exercise should have a separate section in the lab-report document.

Your lab grade will be based upon

1.        the formatting of your source code;

2.        the use of meaningful identifiers;

3.        the extent of internal documentation;

4.        the degree to which an exercises’ specifications are met; and

5.        the completeness of your lab report.



iLAB STEPS

STEP 1: Create a Multifile Project



Create a new multifile project using the Resistor class developed in Week 1, and include a new
main() test function.

STEP 2: Modify the Resistor-Class Definition

1.        Add a static data member of the class Resistor to keep track of the number of Resistor
objects that are dynamically created. This will also be used to limit the number of objects that are
dynamically created to the maximum array size of the pointer array in the test function main().

2.         In the Resistor constructor, use a random-number generator to randomly assign a
nominal resistance value to the object between 1,000 and 10,000 ohms. The resistance values are
not required to be standard resistance values.

STEP 3: Create the Test Function Main() and the Support Function

1.        Create an array of pointers of type Resistor.

2.         Use elements of the pointer array to allow the user to dynamically allocate memory and to
instantiate objects of the Resistor class.

3.      Use the indirect member-selection operator (pointer) in the test routine to access function
members of the Resistor class.
4.        Write a new, nonclass function called in function main() to sort the pointers to the
Resistor objects in order from lowest nominal resistance value to highest, passing a pointer to the
Resistor-object pointer as the only passed data argument.

5.         Display the sorted Resistor objects according to the nominal resistance value, from lowest
to highest.

6.         Within the sorting function, use pointer arithmetic to access the individual Resistor
objects.

7.         Function main() should also ensure that there are no memory leaks when the program
ends.


CLICK HERE TO GET THE SOLUTION !!!!!!!!

Más contenido relacionado

La actualidad más candente

Prelim Project OOP
Prelim Project OOPPrelim Project OOP
Prelim Project OOPDwight Sabio
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingVIKASH MAINANWAL
 
Duplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #Salesforce
Duplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #SalesforceDuplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #Salesforce
Duplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #SalesforceAmit Singh
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.comDavisMurphyB81
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Adi Bolboaca
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and DynamicSneh Pahilwani
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner classsimarsimmygrewal
 
Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3Bianca Teşilă
 
Effective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsEffective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsRoshan Deniyage
 
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Virtual Forge
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2Bianca Teşilă
 
Why you should use a testing framework
Why you should use a testing frameworkWhy you should use a testing framework
Why you should use a testing frameworkRichie Cotton
 
OOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETOOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETjinaldesailive
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner classdeepsxn
 

La actualidad más candente (20)

Prelim Project OOP
Prelim Project OOPPrelim Project OOP
Prelim Project OOP
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handling
 
Duplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #Salesforce
Duplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #SalesforceDuplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #Salesforce
Duplicate Contact Trigger || Trigger Logic Building || #ApexTrigger #Salesforce
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and Dynamic
 
Var arg methods
Var arg methodsVar arg methods
Var arg methods
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner class
 
Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3
 
Effective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsEffective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload Varargs
 
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Unit 5
Unit 5Unit 5
Unit 5
 
Ecet 370 week 2 lab 2
Ecet 370 week 2 lab 2Ecet 370 week 2 lab 2
Ecet 370 week 2 lab 2
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2
 
Why you should use a testing framework
Why you should use a testing frameworkWhy you should use a testing framework
Why you should use a testing framework
 
OOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETOOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NET
 
Bad smells in code
Bad smells in codeBad smells in code
Bad smells in code
 
Functions
FunctionsFunctions
Functions
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
 

Destacado

Destacado (6)

Readiness to Stand For Jesus
Readiness to Stand For JesusReadiness to Stand For Jesus
Readiness to Stand For Jesus
 
Dunn_Converter_Cost-Acct
Dunn_Converter_Cost-AcctDunn_Converter_Cost-Acct
Dunn_Converter_Cost-Acct
 
Vietnam promotion tours
Vietnam promotion toursVietnam promotion tours
Vietnam promotion tours
 
Footsteps indochina product v2.0
Footsteps indochina product v2.0Footsteps indochina product v2.0
Footsteps indochina product v2.0
 
Erasmus+ Sharing tools: e-portfolio, e-book
Erasmus+ Sharing tools: e-portfolio, e-bookErasmus+ Sharing tools: e-portfolio, e-book
Erasmus+ Sharing tools: e-portfolio, e-book
 
University of Michigan Sport Business Conference Recap #MSBC2014
University of Michigan Sport Business Conference Recap #MSBC2014University of Michigan Sport Business Conference Recap #MSBC2014
University of Michigan Sport Business Conference Recap #MSBC2014
 

Similar a Comp 220 ilab 5 of 7

Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7helpido9
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programmingsmumbahelp
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programmingsmumbahelp
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Abdul Hannan
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-contentAmanCSE1
 
Core java-training-course-content
Core java-training-course-contentCore java-training-course-content
Core java-training-course-contentvenkateshcs6
 
Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-contentAmanCSE1
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docxhoney725342
 
Learning to Rank Relevant Files for Bug Reports using Domain Knowledge
Learning to Rank Relevant Files for Bug Reports using Domain KnowledgeLearning to Rank Relevant Files for Bug Reports using Domain Knowledge
Learning to Rank Relevant Files for Bug Reports using Domain KnowledgeXin Ye
 
Assignment1 B 0
Assignment1 B 0Assignment1 B 0
Assignment1 B 0Mahmoud
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxalfred4lewis58146
 
QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6Akash Tyagi
 
ITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docxITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docxchristiandean12115
 

Similar a Comp 220 ilab 5 of 7 (20)

Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
17515
1751517515
17515
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-content
 
Core java-training-course-content
Core java-training-course-contentCore java-training-course-content
Core java-training-course-content
 
Core java-course-content
Core java-course-contentCore java-course-content
Core java-course-content
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docx
 
Learning to Rank Relevant Files for Bug Reports using Domain Knowledge
Learning to Rank Relevant Files for Bug Reports using Domain KnowledgeLearning to Rank Relevant Files for Bug Reports using Domain Knowledge
Learning to Rank Relevant Files for Bug Reports using Domain Knowledge
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
Assignment1 B 0
Assignment1 B 0Assignment1 B 0
Assignment1 B 0
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docx
 
QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6
 
ITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docxITECH 2100 Programming 2 School of Science, Information Te.docx
ITECH 2100 Programming 2 School of Science, Information Te.docx
 
Java
JavaJava
Java
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
l2-es6-160830040119.pdf
l2-es6-160830040119.pdfl2-es6-160830040119.pdf
l2-es6-160830040119.pdf
 

Más de ashhadiqbal

Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6ashhadiqbal
 
Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6ashhadiqbal
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6ashhadiqbal
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6ashhadiqbal
 
Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6ashhadiqbal
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7ashhadiqbal
 
CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7ashhadiqbal
 
CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7ashhadiqbal
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7ashhadiqbal
 

Más de ashhadiqbal (13)

Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
 
Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6
 
Ilab 2 of 7
Ilab 2 of 7Ilab 2 of 7
Ilab 2 of 7
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
 
CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7
 
CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7
 
PRG/421 Week 4
PRG/421 Week 4PRG/421 Week 4
PRG/421 Week 4
 
PRG/421 Week 2
PRG/421 Week 2PRG/421 Week 2
PRG/421 Week 2
 
PRG/421 Week 1
PRG/421 Week 1PRG/421 Week 1
PRG/421 Week 1
 

Comp 220 ilab 5 of 7

  • 1. COMP/220 iLab 5 of 7 - C++ Course iLab 5 of 7: Pointers and Pointer Operations iLAB OVERVIEW Scenario and Summary This lab will explore the use of pointers in several ways. Pointers will be used to dynamically allocate memory for new class objects on demand from the user, and they will be used to access class- member functions. Pointer arithmetic will be used to access and sort class objects according to criteria explained in the lab. Pointers are, essentially, address variables, or variables that hold as their value the address of other variables. In terms of memory management, they are very powerful devices, and they more closely and efficiently use the actual internal hardware registers of the microprocessor that the program operates on. Pointers also have the requirement that the pointer type must be of the same data type as the variable, or the data that it points to or holds the address of. The power of pointers also hints at the potential complexity of their use, which is why this lab is focused almost entirely on several different aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers. The Resistor class created in the Week 2 lab will be used as the class that the pointer operations will be used upon. The lab also requires the use of accessor functions and static data members, which may need to be added to the Resistor class definition and implementation. Deliverables 1. Submit a single Notepad file containing the source code for all the files of the lab to the Dropbox for Week 5. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example, YourLastName_Lab5.txt. Each program should include a comment section that includes, at a minimum, your name, the lab and exercise number, and a description of what the program accomplishes. 2. Submit a lab report (a Word document) containing the following information to the Dropbox for Week 5. o Include your name and the lab or lab-exercise number. o Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output. o Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.
  • 2. o Summary and Conclusions: Write a statement summarizing your predicted and actual output, and identify and explain any differences. For conclusions, write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise. o A UML diagram: This should show all classes, class members, access specifiers, data types, and function arguments, along with any and all class-to-class relationships. o Answers to Lab Questions: Answer any and all lab questions included in the lab steps. Each lab exercise should have a separate section in the lab-report document. Your lab grade will be based upon 1. the formatting of your source code; 2. the use of meaningful identifiers; 3. the extent of internal documentation; 4. the degree to which an exercises’ specifications are met; and 5. the completeness of your lab report. iLAB STEPS STEP 1: Create a Multifile Project Create a new multifile project using the Resistor class developed in Week 1, and include a new main() test function. STEP 2: Modify the Resistor-Class Definition 1. Add a static data member of the class Resistor to keep track of the number of Resistor objects that are dynamically created. This will also be used to limit the number of objects that are dynamically created to the maximum array size of the pointer array in the test function main(). 2. In the Resistor constructor, use a random-number generator to randomly assign a nominal resistance value to the object between 1,000 and 10,000 ohms. The resistance values are not required to be standard resistance values. STEP 3: Create the Test Function Main() and the Support Function 1. Create an array of pointers of type Resistor. 2. Use elements of the pointer array to allow the user to dynamically allocate memory and to instantiate objects of the Resistor class. 3. Use the indirect member-selection operator (pointer) in the test routine to access function members of the Resistor class.
  • 3. 4. Write a new, nonclass function called in function main() to sort the pointers to the Resistor objects in order from lowest nominal resistance value to highest, passing a pointer to the Resistor-object pointer as the only passed data argument. 5. Display the sorted Resistor objects according to the nominal resistance value, from lowest to highest. 6. Within the sorting function, use pointer arithmetic to access the individual Resistor objects. 7. Function main() should also ensure that there are no memory leaks when the program ends. CLICK HERE TO GET THE SOLUTION !!!!!!!!