SlideShare une entreprise Scribd logo
1  sur  3
In the dynArray.cpp file, a template class DynArray is needed for it to correctly compile and
display the given output when executed.
Sample output:
0 1.68294 1.81859 0.28224 -1.5136
0 1 1 0 -1
// dynArray.cpp
#include <iostream>
#include <math.h>
#include "DynArray.h"
using namespace std;
template <class A, class X>
void set_five ( A& a ) {
X x=0;
for ( int i=0; i<5; i++ ) {
x = (X)( 2.0*sin(double(i)) );
a.add ( x );
cout << a[i] << " ";
}
cout << endl;
}
int main(int argc, const char * argv[])
{
DynArray<float> fa;
set_five<DynArray<float>,float> ( fa );
DynArray<int> ia;
set_five<DynArray<int>,int> ( ia );
return 0;
}
Solution
Template<class DynArray>
class DynArray
{
template <class A, class X>
void set_five ( A& a ) {
X x=0;
for ( int i=0; i<5; i++ ) {
x = (X)( 2.0*sin(double(i)) );
a.add ( x );
cout << a[i] << " ";
}
cout << endl;
}
int main(int argc, const char * argv[])
{
DynArray<float> fa;
set_five<DynArray<float>,float> ( fa );
DynArray<int> ia;
set_five<DynArray<int>,int> ( ia );
return 0;
}
}
In the dynArray-cpp file- a template class DynArray is needed for it t.docx

Contenu connexe

Similaire à In the dynArray-cpp file- a template class DynArray is needed for it t.docx

C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
herminaherman
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
웅식 전
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 

Similaire à In the dynArray-cpp file- a template class DynArray is needed for it t.docx (20)

12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Array Cont
Array ContArray Cont
Array Cont
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
 
data_structure (1).pptx
data_structure (1).pptxdata_structure (1).pptx
data_structure (1).pptx
 
Data struture lab
Data struture labData struture lab
Data struture lab
 
7 functions
7  functions7  functions
7 functions
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C programming
C programmingC programming
C programming
 

Plus de carold12

In its income statement for the year ended December 31- 2014- Gavin Co.docx
In its income statement for the year ended December 31- 2014- Gavin Co.docxIn its income statement for the year ended December 31- 2014- Gavin Co.docx
In its income statement for the year ended December 31- 2014- Gavin Co.docx
carold12
 
In the USA are we currently in a period of recession or inflation- Exp.docx
In the USA are we currently in a period of recession or inflation- Exp.docxIn the USA are we currently in a period of recession or inflation- Exp.docx
In the USA are we currently in a period of recession or inflation- Exp.docx
carold12
 
In this Discussion- you will be able to familiarize yourself with the.docx
In this Discussion- you will be able to familiarize yourself with the.docxIn this Discussion- you will be able to familiarize yourself with the.docx
In this Discussion- you will be able to familiarize yourself with the.docx
carold12
 

Plus de carold12 (18)

In scilab Write a function named countDown that accepts a total time T.docx
In scilab Write a function named countDown that accepts a total time T.docxIn scilab Write a function named countDown that accepts a total time T.docx
In scilab Write a function named countDown that accepts a total time T.docx
 
In managing processes within organizations- what type(s) of methodolog.docx
In managing processes within organizations- what type(s) of methodolog.docxIn managing processes within organizations- what type(s) of methodolog.docx
In managing processes within organizations- what type(s) of methodolog.docx
 
in Java For any element in keysList with a value greater than 100- pri.docx
in Java For any element in keysList with a value greater than 100- pri.docxin Java For any element in keysList with a value greater than 100- pri.docx
in Java For any element in keysList with a value greater than 100- pri.docx
 
In Iate 2012- the Micklaus Corporation was formed- The corporate chart.docx
In Iate 2012- the Micklaus Corporation was formed- The corporate chart.docxIn Iate 2012- the Micklaus Corporation was formed- The corporate chart.docx
In Iate 2012- the Micklaus Corporation was formed- The corporate chart.docx
 
In Fall 1999- people in the financial community were making their fina.docx
In Fall 1999- people in the financial community were making their fina.docxIn Fall 1999- people in the financial community were making their fina.docx
In Fall 1999- people in the financial community were making their fina.docx
 
In its income statement for the year ended December 31- 2014- Gavin Co.docx
In its income statement for the year ended December 31- 2014- Gavin Co.docxIn its income statement for the year ended December 31- 2014- Gavin Co.docx
In its income statement for the year ended December 31- 2014- Gavin Co.docx
 
in thin layer chromatography aspirin and caffeine were used as spot- u.docx
in thin layer chromatography aspirin and caffeine were used as spot- u.docxin thin layer chromatography aspirin and caffeine were used as spot- u.docx
in thin layer chromatography aspirin and caffeine were used as spot- u.docx
 
In the USA are we currently in a period of recession or inflation- Exp.docx
In the USA are we currently in a period of recession or inflation- Exp.docxIn the USA are we currently in a period of recession or inflation- Exp.docx
In the USA are we currently in a period of recession or inflation- Exp.docx
 
In this Discussion- you will be able to familiarize yourself with the.docx
In this Discussion- you will be able to familiarize yourself with the.docxIn this Discussion- you will be able to familiarize yourself with the.docx
In this Discussion- you will be able to familiarize yourself with the.docx
 
In the US economy we have two sectors- private and public sectors- In.docx
In the US economy we have two sectors- private and public sectors- In.docxIn the US economy we have two sectors- private and public sectors- In.docx
In the US economy we have two sectors- private and public sectors- In.docx
 
In the traditional systems development life cycle- users- Are importan.docx
In the traditional systems development life cycle- users- Are importan.docxIn the traditional systems development life cycle- users- Are importan.docx
In the traditional systems development life cycle- users- Are importan.docx
 
3) IR Spec When it comes to IR analysis- one can choose different meth.docx
3) IR Spec When it comes to IR analysis- one can choose different meth.docx3) IR Spec When it comes to IR analysis- one can choose different meth.docx
3) IR Spec When it comes to IR analysis- one can choose different meth.docx
 
3) Distinguish among various methods to implement access controlsSolut.docx
3) Distinguish among various methods to implement access controlsSolut.docx3) Distinguish among various methods to implement access controlsSolut.docx
3) Distinguish among various methods to implement access controlsSolut.docx
 
2D-Array How is the address of an individual element of a 2-dimensiona.docx
2D-Array How is the address of an individual element of a 2-dimensiona.docx2D-Array How is the address of an individual element of a 2-dimensiona.docx
2D-Array How is the address of an individual element of a 2-dimensiona.docx
 
28- How does the total vapor pressure (VP) and freezing point (FP) of.docx
28- How does the total vapor pressure (VP) and freezing point (FP) of.docx28- How does the total vapor pressure (VP) and freezing point (FP) of.docx
28- How does the total vapor pressure (VP) and freezing point (FP) of.docx
 
27- The Bohr m odel of the hydrogen atom includes which of the followi.docx
27- The Bohr m odel of the hydrogen atom includes which of the followi.docx27- The Bohr m odel of the hydrogen atom includes which of the followi.docx
27- The Bohr m odel of the hydrogen atom includes which of the followi.docx
 
25- Question Part Points Submissions Used 1.docx
25-       Question Part   Points   Submissions Used         1.docx25-       Question Part   Points   Submissions Used         1.docx
25- Question Part Points Submissions Used 1.docx
 
3- Suppose that U-S- government actively uses the fiscal policy to fig.docx
3- Suppose that U-S- government actively uses the fiscal policy to fig.docx3- Suppose that U-S- government actively uses the fiscal policy to fig.docx
3- Suppose that U-S- government actively uses the fiscal policy to fig.docx
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Dernier (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
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
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

In the dynArray-cpp file- a template class DynArray is needed for it t.docx

  • 1. In the dynArray.cpp file, a template class DynArray is needed for it to correctly compile and display the given output when executed. Sample output: 0 1.68294 1.81859 0.28224 -1.5136 0 1 1 0 -1 // dynArray.cpp #include <iostream> #include <math.h> #include "DynArray.h" using namespace std; template <class A, class X> void set_five ( A& a ) { X x=0; for ( int i=0; i<5; i++ ) { x = (X)( 2.0*sin(double(i)) ); a.add ( x ); cout << a[i] << " "; } cout << endl; } int main(int argc, const char * argv[]) { DynArray<float> fa; set_five<DynArray<float>,float> ( fa ); DynArray<int> ia; set_five<DynArray<int>,int> ( ia ); return 0; }
  • 2. Solution Template<class DynArray> class DynArray { template <class A, class X> void set_five ( A& a ) { X x=0; for ( int i=0; i<5; i++ ) { x = (X)( 2.0*sin(double(i)) ); a.add ( x ); cout << a[i] << " "; } cout << endl; } int main(int argc, const char * argv[]) { DynArray<float> fa; set_five<DynArray<float>,float> ( fa ); DynArray<int> ia; set_five<DynArray<int>,int> ( ia ); return 0; } }