SlideShare a Scribd company logo
1 of 3
I made the code below, however I have a problem in the test code like 'a.out: ex2.cpp:20: int
main(): Assertion
`countOccurrences(a,1,6) == 2' failed. Aborted'.
what is the problem of my test code?
# include <iostream>
#include <cassert>
using namespace std;
int countOccurrences(int a[], int len, int k){
int occurrences = 0;
for (int i = 0; i < len; ++i){
if (a[i] == k) ++occurrences;
}
return occurrences;
}
int main(){
int a[] = {1, 1, 5, 7, -11, 23};
assert(countOccurrences(a,1,6) == 2);
assert(countOccurrences(a,2,6) == 0);
assert(countOccurrences(a,5,6) == 1);
assert(countOccurrences(a,7,6) == 1);
assert(countOccurrences(a,-11,6) == 1);
assert(countOccurrences(a,23,6) == 1);
}
I made this
Solution
Hi,
I have updated your code. There is an issue with parameter mapping from calling function to
called function. Highlighted the code changes. it is working fine now.
#include <iostream>
#include <cassert>
using namespace std;
//int countOccurrences(int a[], int len, int k){
int countOccurrences(int a[], int k, int len ){
int occurrences = 0;
for (int i = 0; i < len; ++i){
if (a[i] == k) ++occurrences;
}
return occurrences;
}
int main(){
int a[] = {1, 1, 5, 7, -11, 23};
assert(countOccurrences(a,1,6) == 2);
assert(countOccurrences(a,2,6) == 0);
assert(countOccurrences(a,5,6) == 1);
assert(countOccurrences(a,7,6) == 1);
assert(countOccurrences(a,-11,6) == 1);
assert(countOccurrences(a,23,6) == 1);
}
I made the code below- however I have a problem in the test code like.docx

More Related Content

Similar to I made the code below- however I have a problem in the test code like.docx

Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersRick Beerendonk
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test frameworkAbner Chih Yi Huang
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfChen-Hung Hu
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
Optimization in the world of 64-bit errors
Optimization  in the world of 64-bit errorsOptimization  in the world of 64-bit errors
Optimization in the world of 64-bit errorsPVS-Studio
 
evil_server.cpp#include string #include cstdlib #include.pdf
evil_server.cpp#include string #include cstdlib #include.pdfevil_server.cpp#include string #include cstdlib #include.pdf
evil_server.cpp#include string #include cstdlib #include.pdffortmdu
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the mastersAra Pehlivanian
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorNeeraj Kaushik
 
Review questions and answers
Review questions and answersReview questions and answers
Review questions and answersIIUM
 
Produce a new version of k-means called MR-K-means(Multi-run K-mean.pdf
Produce a new version of k-means called MR-K-means(Multi-run K-mean.pdfProduce a new version of k-means called MR-K-means(Multi-run K-mean.pdf
Produce a new version of k-means called MR-K-means(Multi-run K-mean.pdfmeejuhaszjasmynspe52
 
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfSolve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfsnewfashion
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control StructureMohammad Shaker
 

Similar to I made the code below- however I have a problem in the test code like.docx (20)

informatics practices practical file
informatics practices practical fileinformatics practices practical file
informatics practices practical file
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
Review version 4
Review version 4Review version 4
Review version 4
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Optimization in the world of 64-bit errors
Optimization  in the world of 64-bit errorsOptimization  in the world of 64-bit errors
Optimization in the world of 64-bit errors
 
evil_server.cpp#include string #include cstdlib #include.pdf
evil_server.cpp#include string #include cstdlib #include.pdfevil_server.cpp#include string #include cstdlib #include.pdf
evil_server.cpp#include string #include cstdlib #include.pdf
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
Review questions and answers
Review questions and answersReview questions and answers
Review questions and answers
 
Produce a new version of k-means called MR-K-means(Multi-run K-mean.pdf
Produce a new version of k-means called MR-K-means(Multi-run K-mean.pdfProduce a new version of k-means called MR-K-means(Multi-run K-mean.pdf
Produce a new version of k-means called MR-K-means(Multi-run K-mean.pdf
 
C programs
C programsC programs
C programs
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
901131 examples
901131 examples901131 examples
901131 examples
 
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfSolve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 

More from cwayne3

I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxcwayne3
 
I need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxI need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxcwayne3
 
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxi Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxcwayne3
 
How would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxHow would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxcwayne3
 
How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxcwayne3
 
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docxcwayne3
 
10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docxcwayne3
 
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docxcwayne3
 
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docxcwayne3
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docxcwayne3
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docxcwayne3
 
1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docxcwayne3
 
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docxcwayne3
 
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docxcwayne3
 
1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docxcwayne3
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docxcwayne3
 

More from cwayne3 (16)

I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docx
 
I need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxI need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docx
 
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxi Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
 
How would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxHow would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docx
 
How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docx
 
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
 
10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx
 
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
 
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
 
1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx
 
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
 
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
 
1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
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
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
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
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
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...
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
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
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
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
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

I made the code below- however I have a problem in the test code like.docx

  • 1. I made the code below, however I have a problem in the test code like 'a.out: ex2.cpp:20: int main(): Assertion `countOccurrences(a,1,6) == 2' failed. Aborted'. what is the problem of my test code? # include <iostream> #include <cassert> using namespace std; int countOccurrences(int a[], int len, int k){ int occurrences = 0; for (int i = 0; i < len; ++i){ if (a[i] == k) ++occurrences; } return occurrences; } int main(){ int a[] = {1, 1, 5, 7, -11, 23}; assert(countOccurrences(a,1,6) == 2); assert(countOccurrences(a,2,6) == 0); assert(countOccurrences(a,5,6) == 1); assert(countOccurrences(a,7,6) == 1); assert(countOccurrences(a,-11,6) == 1); assert(countOccurrences(a,23,6) == 1); } I made this
  • 2. Solution Hi, I have updated your code. There is an issue with parameter mapping from calling function to called function. Highlighted the code changes. it is working fine now. #include <iostream> #include <cassert> using namespace std; //int countOccurrences(int a[], int len, int k){ int countOccurrences(int a[], int k, int len ){ int occurrences = 0; for (int i = 0; i < len; ++i){ if (a[i] == k) ++occurrences; } return occurrences; } int main(){ int a[] = {1, 1, 5, 7, -11, 23}; assert(countOccurrences(a,1,6) == 2); assert(countOccurrences(a,2,6) == 0); assert(countOccurrences(a,5,6) == 1); assert(countOccurrences(a,7,6) == 1); assert(countOccurrences(a,-11,6) == 1); assert(countOccurrences(a,23,6) == 1); }