SlideShare a Scribd company logo
Below is the assignment description and the file I have written. I would love to test this file to
make sure that everything is satisfied (vector with all modes in ascending order). I'm having a
really hard time constructing a main method to test it. Help!!
-------------------------------------------------------
The mode is the value that appears most often in a set of data. Write a function named findMode
that takes as parameters an array of int and the size of the array, and returns a vector containing
the mode(s). If there is just a single most frequent value, the vector will only contain that one
value, but if multiple values tie for maximum frequency, the vector will need to contain all such
values. This includes the case where every number in the array appears only once. Each mode
should appear only once in the vector. The values in the vector that is returned must be in
ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the
beginning and end of the vector look a little bit different. If your vector is named result, then it
would look like this: "std::sort(result.begin(), result.end());".
-------------------------------------------------------
#include // needed for the sort() function
#include // needed to use the vector type
#include // needed for the main function
using std::vector;
using std::sort;
vector findMode(int array[], int size)
{
int maxFreq = 1; // initalizing the largest frequency to be 1
vector result; // results is an empty vector
//Initializing the loop through the integer array
for (int i = 0; i < size; i++)
{
int count = 1; //started the counter at 1
//started the the loop after the 1st entry, looking for matches with the value at index i.
for (int j = i + 1; j < size; j++)
{
//if an entry matches another, then add one to the counter
if (array[i] == array[j])
{
count++;
}
}
//when the counter is equal to the max frequency, the integer is added to the result vector.
if (count == maxFreq)
{
result.push_back(array[i]);
}
//when the counter for i is greater than the max frequency, updates the maxFreq, clear the values
stored in the result vector, and push the value to the empty vector.
if (count > maxFreq)
{
maxFreq = count;
result.clear();
result.push_back(array[i]);
}
}
//sort the modes in ascending order
sort(result.begin(), result.end());
return result;
Below is the assignment description and the file I have written. I would love to test this file to
make sure that everything is satisfied (vector with all modes in ascending order). I'm having a
really hard time constructing a main method to test it. Help!!
-------------------------------------------------------
The mode is the value that appears most often in a set of data. Write a function named findMode
that takes as parameters an array of int and the size of the array, and returns a vector containing
the mode(s). If there is just a single most frequent value, the vector will only contain that one
value, but if multiple values tie for maximum frequency, the vector will need to contain all such
values. This includes the case where every number in the array appears only once. Each mode
should appear only once in the vector. The values in the vector that is returned must be in
ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the
beginning and end of the vector look a little bit different. If your vector is named result, then it
would look like this: "std::sort(result.begin(), result.end());".
-------------------------------------------------------
#include // needed for the sort() function
#include // needed to use the vector type
#include // needed for the main function
using std::vector;
using std::sort;
vector findMode(int array[], int size)
{
int maxFreq = 1; // initalizing the largest frequency to be 1
vector result; // results is an empty vector
//Initializing the loop through the integer array
for (int i = 0; i < size; i++)
{
int count = 1; //started the counter at 1
//started the the loop after the 1st entry, looking for matches with the value at index i.
for (int j = i + 1; j < size; j++)
{
//if an entry matches another, then add one to the counter
if (array[i] == array[j])
{
count++;
}
}
//when the counter is equal to the max frequency, the integer is added to the result vector.
if (count == maxFreq)
{
result.push_back(array[i]);
}
//when the counter for i is greater than the max frequency, updates the maxFreq, clear the values
stored in the result vector, and push the value to the empty vector.
if (count > maxFreq)
{
maxFreq = count;
result.clear();
result.push_back(array[i]);
}
}
//sort the modes in ascending order
sort(result.begin(), result.end());
return result;
Below is the assignment description and the file I have written. I would love to test this file to
make sure that everything is satisfied (vector with all modes in ascending order). I'm having a
really hard time constructing a main method to test it. Help!!
-------------------------------------------------------
The mode is the value that appears most often in a set of data. Write a function named findMode
that takes as parameters an array of int and the size of the array, and returns a vector containing
the mode(s). If there is just a single most frequent value, the vector will only contain that one
value, but if multiple values tie for maximum frequency, the vector will need to contain all such
values. This includes the case where every number in the array appears only once. Each mode
should appear only once in the vector. The values in the vector that is returned must be in
ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the
beginning and end of the vector look a little bit different. If your vector is named result, then it
would look like this: "std::sort(result.begin(), result.end());".
The mode is the value that appears most often in a set of data. Write a function named findMode
that takes as parameters an array of int and the size of the array, and returns a vector containing
the mode(s). If there is just a single most frequent value, the vector will only contain that one
value, but if multiple values tie for maximum frequency, the vector will need to contain all such
values. This includes the case where every number in the array appears only once. Each mode
should appear only once in the vector. The values in the vector that is returned must be in
ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the
beginning and end of the vector look a little bit different. If your vector is named result, then it
would look like this: "std::sort(result.begin(), result.end());".
-------------------------------------------------------
#include // needed for the sort() function
#include // needed to use the vector type
#include // needed for the main function
using std::vector;
using std::sort;
vector findMode(int array[], int size)
{
int maxFreq = 1; // initalizing the largest frequency to be 1
vector result; // results is an empty vector
//Initializing the loop through the integer array
for (int i = 0; i < size; i++)
{
int count = 1; //started the counter at 1
//started the the loop after the 1st entry, looking for matches with the value at index i.
for (int j = i + 1; j < size; j++)
{
//if an entry matches another, then add one to the counter
if (array[i] == array[j])
{
count++;
}
}
//when the counter is equal to the max frequency, the integer is added to the result vector.
if (count == maxFreq)
{
result.push_back(array[i]);
}
//when the counter for i is greater than the max frequency, updates the maxFreq, clear the values
stored in the result vector, and push the value to the empty vector.
if (count > maxFreq)
{
maxFreq = count;
result.clear();
result.push_back(array[i]);
}
}
//sort the modes in ascending order
sort(result.begin(), result.end());
return result;
Solution
Here is your main method, Copy Paste This code and Replace your main method using the below
Code.
int main()
{
//Case 1
// int arr[10]= {1,1,1,1,1,1,1,2,3,4};
//vector result = findMode(arr,10);
//Case 2
// int arr[10]= {1,2,3,4};
//vector result = findMode(arr,4);
//Case 3
// int arr[1]= {1};
//vector result = findMode(arr,1);
//Case 4
// int arr[10]= {1,1,2,2,3,3};
//vector result = findMode(arr,6);
int arr[10]= {1,1,2,2,3,3};
vector result = findMode(arr,6);
for (std::vector::iterator it = result.begin() ; it != result.end(); ++it)
std::cout << ' ' << *it;
}
I have written few more Tests for you, you can uncomment them and test your code using those
inputs. I hope it helps.

More Related Content

Similar to Below is the assignment description and the file I have written..pdf

Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
admin463580
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
herminaherman
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
stopgolook
 
ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docx
vannagoforth
 
Enumerable
EnumerableEnumerable
Enumerable
mussawir20
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
TaseerRao
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
Yaser Zhian
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
Isaac9LjWelchq
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
ankit11134
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
worldchannel
 
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
aloeplusint
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
info114
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdf
leventhalbrad49439
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
Program 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdfProgram 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdf
ezhilvizhiyan
 

Similar to Below is the assignment description and the file I have written..pdf (20)

Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
Array assignment
Array assignmentArray assignment
Array assignment
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
 
ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docx
 
Enumerable
EnumerableEnumerable
Enumerable
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdfStep 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
Step 1You need to run the JAVA programs in sections 3.3 and 3.5 for.pdf
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdf
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Program 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdfProgram 1 (Practicing an example of function using call by referenc.pdf
Program 1 (Practicing an example of function using call by referenc.pdf
 

More from info673628

Firms HL and LL are identical except for their leverage ratios and t.pdf
Firms HL and LL are identical except for their leverage ratios and t.pdfFirms HL and LL are identical except for their leverage ratios and t.pdf
Firms HL and LL are identical except for their leverage ratios and t.pdf
info673628
 
Find the domain of the composite function fog. 1 The domain contains .pdf
Find the domain of the composite function fog. 1 The domain contains .pdfFind the domain of the composite function fog. 1 The domain contains .pdf
Find the domain of the composite function fog. 1 The domain contains .pdf
info673628
 
Do the following two problems1. Any algorithm that solves the sea.pdf
Do the following two problems1. Any algorithm that solves the sea.pdfDo the following two problems1. Any algorithm that solves the sea.pdf
Do the following two problems1. Any algorithm that solves the sea.pdf
info673628
 
Describe two traits that represent a sustainable societyand two tr.pdf
Describe two traits that represent a sustainable societyand two tr.pdfDescribe two traits that represent a sustainable societyand two tr.pdf
Describe two traits that represent a sustainable societyand two tr.pdf
info673628
 
Compare Windows Assembly to that of a UNIX system.SolutionTher.pdf
Compare Windows Assembly to that of a UNIX system.SolutionTher.pdfCompare Windows Assembly to that of a UNIX system.SolutionTher.pdf
Compare Windows Assembly to that of a UNIX system.SolutionTher.pdf
info673628
 
You have prepared the spread plates below using 0.1 mL from a liquid .pdf
You have prepared the spread plates below using 0.1 mL from a liquid .pdfYou have prepared the spread plates below using 0.1 mL from a liquid .pdf
You have prepared the spread plates below using 0.1 mL from a liquid .pdf
info673628
 
While bacteria exhibit simple cell division where the quantity o.pdf
While bacteria exhibit simple cell division where the quantity o.pdfWhile bacteria exhibit simple cell division where the quantity o.pdf
While bacteria exhibit simple cell division where the quantity o.pdf
info673628
 
Which of the following items appears on the income statement before i.pdf
Which of the following items appears on the income statement before i.pdfWhich of the following items appears on the income statement before i.pdf
Which of the following items appears on the income statement before i.pdf
info673628
 
What part of the root is responsible for water and nutrient absorptio.pdf
What part of the root is responsible for water and nutrient absorptio.pdfWhat part of the root is responsible for water and nutrient absorptio.pdf
What part of the root is responsible for water and nutrient absorptio.pdf
info673628
 
What is the purpose of the balance sheet Be sure to discuss the thr.pdf
What is the purpose of the balance sheet Be sure to discuss the thr.pdfWhat is the purpose of the balance sheet Be sure to discuss the thr.pdf
What is the purpose of the balance sheet Be sure to discuss the thr.pdf
info673628
 
What is culture Why should culture play a role in aiding our unders.pdf
What is culture Why should culture play a role in aiding our unders.pdfWhat is culture Why should culture play a role in aiding our unders.pdf
What is culture Why should culture play a role in aiding our unders.pdf
info673628
 
What are the Federal Reserves major assets and liabilities What a.pdf
What are the Federal Reserves major assets and liabilities What a.pdfWhat are the Federal Reserves major assets and liabilities What a.pdf
What are the Federal Reserves major assets and liabilities What a.pdf
info673628
 
Use whichever properties (associative andor communities) are nece.pdf
Use whichever properties (associative andor communities) are nece.pdfUse whichever properties (associative andor communities) are nece.pdf
Use whichever properties (associative andor communities) are nece.pdf
info673628
 
Use a 5 significance level unless specified otherwise.Please give.pdf
Use a 5 significance level unless specified otherwise.Please give.pdfUse a 5 significance level unless specified otherwise.Please give.pdf
Use a 5 significance level unless specified otherwise.Please give.pdf
info673628
 
two children own two-way radios that have a maximum range of 2 miles.pdf
two children own two-way radios that have a maximum range of 2 miles.pdftwo children own two-way radios that have a maximum range of 2 miles.pdf
two children own two-way radios that have a maximum range of 2 miles.pdf
info673628
 
The place within an enzyme where a substrate binds is called the ATP.pdf
The place within an enzyme where a substrate binds is called the  ATP.pdfThe place within an enzyme where a substrate binds is called the  ATP.pdf
The place within an enzyme where a substrate binds is called the ATP.pdf
info673628
 
READ BEFORE YOU START Please read the given Word document fo.pdf
READ BEFORE YOU START  Please read the given Word document fo.pdfREAD BEFORE YOU START  Please read the given Word document fo.pdf
READ BEFORE YOU START Please read the given Word document fo.pdf
info673628
 
Refer to the table below. A student creates the table above as a stu.pdf
Refer to the table below.  A student creates the table above as a stu.pdfRefer to the table below.  A student creates the table above as a stu.pdf
Refer to the table below. A student creates the table above as a stu.pdf
info673628
 
prove the followings1- every subset of a finite set is finite2-.pdf
prove the followings1- every subset of a finite set is finite2-.pdfprove the followings1- every subset of a finite set is finite2-.pdf
prove the followings1- every subset of a finite set is finite2-.pdf
info673628
 
Problem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdf
Problem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdfProblem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdf
Problem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdf
info673628
 

More from info673628 (20)

Firms HL and LL are identical except for their leverage ratios and t.pdf
Firms HL and LL are identical except for their leverage ratios and t.pdfFirms HL and LL are identical except for their leverage ratios and t.pdf
Firms HL and LL are identical except for their leverage ratios and t.pdf
 
Find the domain of the composite function fog. 1 The domain contains .pdf
Find the domain of the composite function fog. 1 The domain contains .pdfFind the domain of the composite function fog. 1 The domain contains .pdf
Find the domain of the composite function fog. 1 The domain contains .pdf
 
Do the following two problems1. Any algorithm that solves the sea.pdf
Do the following two problems1. Any algorithm that solves the sea.pdfDo the following two problems1. Any algorithm that solves the sea.pdf
Do the following two problems1. Any algorithm that solves the sea.pdf
 
Describe two traits that represent a sustainable societyand two tr.pdf
Describe two traits that represent a sustainable societyand two tr.pdfDescribe two traits that represent a sustainable societyand two tr.pdf
Describe two traits that represent a sustainable societyand two tr.pdf
 
Compare Windows Assembly to that of a UNIX system.SolutionTher.pdf
Compare Windows Assembly to that of a UNIX system.SolutionTher.pdfCompare Windows Assembly to that of a UNIX system.SolutionTher.pdf
Compare Windows Assembly to that of a UNIX system.SolutionTher.pdf
 
You have prepared the spread plates below using 0.1 mL from a liquid .pdf
You have prepared the spread plates below using 0.1 mL from a liquid .pdfYou have prepared the spread plates below using 0.1 mL from a liquid .pdf
You have prepared the spread plates below using 0.1 mL from a liquid .pdf
 
While bacteria exhibit simple cell division where the quantity o.pdf
While bacteria exhibit simple cell division where the quantity o.pdfWhile bacteria exhibit simple cell division where the quantity o.pdf
While bacteria exhibit simple cell division where the quantity o.pdf
 
Which of the following items appears on the income statement before i.pdf
Which of the following items appears on the income statement before i.pdfWhich of the following items appears on the income statement before i.pdf
Which of the following items appears on the income statement before i.pdf
 
What part of the root is responsible for water and nutrient absorptio.pdf
What part of the root is responsible for water and nutrient absorptio.pdfWhat part of the root is responsible for water and nutrient absorptio.pdf
What part of the root is responsible for water and nutrient absorptio.pdf
 
What is the purpose of the balance sheet Be sure to discuss the thr.pdf
What is the purpose of the balance sheet Be sure to discuss the thr.pdfWhat is the purpose of the balance sheet Be sure to discuss the thr.pdf
What is the purpose of the balance sheet Be sure to discuss the thr.pdf
 
What is culture Why should culture play a role in aiding our unders.pdf
What is culture Why should culture play a role in aiding our unders.pdfWhat is culture Why should culture play a role in aiding our unders.pdf
What is culture Why should culture play a role in aiding our unders.pdf
 
What are the Federal Reserves major assets and liabilities What a.pdf
What are the Federal Reserves major assets and liabilities What a.pdfWhat are the Federal Reserves major assets and liabilities What a.pdf
What are the Federal Reserves major assets and liabilities What a.pdf
 
Use whichever properties (associative andor communities) are nece.pdf
Use whichever properties (associative andor communities) are nece.pdfUse whichever properties (associative andor communities) are nece.pdf
Use whichever properties (associative andor communities) are nece.pdf
 
Use a 5 significance level unless specified otherwise.Please give.pdf
Use a 5 significance level unless specified otherwise.Please give.pdfUse a 5 significance level unless specified otherwise.Please give.pdf
Use a 5 significance level unless specified otherwise.Please give.pdf
 
two children own two-way radios that have a maximum range of 2 miles.pdf
two children own two-way radios that have a maximum range of 2 miles.pdftwo children own two-way radios that have a maximum range of 2 miles.pdf
two children own two-way radios that have a maximum range of 2 miles.pdf
 
The place within an enzyme where a substrate binds is called the ATP.pdf
The place within an enzyme where a substrate binds is called the  ATP.pdfThe place within an enzyme where a substrate binds is called the  ATP.pdf
The place within an enzyme where a substrate binds is called the ATP.pdf
 
READ BEFORE YOU START Please read the given Word document fo.pdf
READ BEFORE YOU START  Please read the given Word document fo.pdfREAD BEFORE YOU START  Please read the given Word document fo.pdf
READ BEFORE YOU START Please read the given Word document fo.pdf
 
Refer to the table below. A student creates the table above as a stu.pdf
Refer to the table below.  A student creates the table above as a stu.pdfRefer to the table below.  A student creates the table above as a stu.pdf
Refer to the table below. A student creates the table above as a stu.pdf
 
prove the followings1- every subset of a finite set is finite2-.pdf
prove the followings1- every subset of a finite set is finite2-.pdfprove the followings1- every subset of a finite set is finite2-.pdf
prove the followings1- every subset of a finite set is finite2-.pdf
 
Problem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdf
Problem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdfProblem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdf
Problem 9-4 Nonconstant growth valuation Hart Enterprises recently pa.pdf
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

Below is the assignment description and the file I have written..pdf

  • 1. Below is the assignment description and the file I have written. I would love to test this file to make sure that everything is satisfied (vector with all modes in ascending order). I'm having a really hard time constructing a main method to test it. Help!! ------------------------------------------------------- The mode is the value that appears most often in a set of data. Write a function named findMode that takes as parameters an array of int and the size of the array, and returns a vector containing the mode(s). If there is just a single most frequent value, the vector will only contain that one value, but if multiple values tie for maximum frequency, the vector will need to contain all such values. This includes the case where every number in the array appears only once. Each mode should appear only once in the vector. The values in the vector that is returned must be in ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the beginning and end of the vector look a little bit different. If your vector is named result, then it would look like this: "std::sort(result.begin(), result.end());". ------------------------------------------------------- #include // needed for the sort() function #include // needed to use the vector type #include // needed for the main function
  • 2. using std::vector; using std::sort; vector findMode(int array[], int size) { int maxFreq = 1; // initalizing the largest frequency to be 1 vector result; // results is an empty vector //Initializing the loop through the integer array for (int i = 0; i < size; i++) {
  • 3. int count = 1; //started the counter at 1 //started the the loop after the 1st entry, looking for matches with the value at index i. for (int j = i + 1; j < size; j++) { //if an entry matches another, then add one to the counter if (array[i] == array[j]) { count++; } } //when the counter is equal to the max frequency, the integer is added to the result vector.
  • 4. if (count == maxFreq) { result.push_back(array[i]); } //when the counter for i is greater than the max frequency, updates the maxFreq, clear the values stored in the result vector, and push the value to the empty vector. if (count > maxFreq) { maxFreq = count; result.clear(); result.push_back(array[i]);
  • 5. } } //sort the modes in ascending order sort(result.begin(), result.end()); return result; Below is the assignment description and the file I have written. I would love to test this file to make sure that everything is satisfied (vector with all modes in ascending order). I'm having a really hard time constructing a main method to test it. Help!! ------------------------------------------------------- The mode is the value that appears most often in a set of data. Write a function named findMode that takes as parameters an array of int and the size of the array, and returns a vector containing the mode(s). If there is just a single most frequent value, the vector will only contain that one value, but if multiple values tie for maximum frequency, the vector will need to contain all such values. This includes the case where every number in the array appears only once. Each mode should appear only once in the vector. The values in the vector that is returned must be in ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the beginning and end of the vector look a little bit different. If your vector is named result, then it would look like this: "std::sort(result.begin(), result.end());".
  • 6. ------------------------------------------------------- #include // needed for the sort() function #include // needed to use the vector type #include // needed for the main function using std::vector; using std::sort; vector findMode(int array[], int size) { int maxFreq = 1; // initalizing the largest frequency to be 1
  • 7. vector result; // results is an empty vector //Initializing the loop through the integer array for (int i = 0; i < size; i++) { int count = 1; //started the counter at 1 //started the the loop after the 1st entry, looking for matches with the value at index i. for (int j = i + 1; j < size; j++) { //if an entry matches another, then add one to the counter
  • 8. if (array[i] == array[j]) { count++; } } //when the counter is equal to the max frequency, the integer is added to the result vector. if (count == maxFreq) { result.push_back(array[i]); } //when the counter for i is greater than the max frequency, updates the maxFreq, clear the values stored in the result vector, and push the value to the empty vector.
  • 9. if (count > maxFreq) { maxFreq = count; result.clear(); result.push_back(array[i]); } } //sort the modes in ascending order sort(result.begin(), result.end()); return result; Below is the assignment description and the file I have written. I would love to test this file to make sure that everything is satisfied (vector with all modes in ascending order). I'm having a
  • 10. really hard time constructing a main method to test it. Help!! ------------------------------------------------------- The mode is the value that appears most often in a set of data. Write a function named findMode that takes as parameters an array of int and the size of the array, and returns a vector containing the mode(s). If there is just a single most frequent value, the vector will only contain that one value, but if multiple values tie for maximum frequency, the vector will need to contain all such values. This includes the case where every number in the array appears only once. Each mode should appear only once in the vector. The values in the vector that is returned must be in ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the beginning and end of the vector look a little bit different. If your vector is named result, then it would look like this: "std::sort(result.begin(), result.end());". The mode is the value that appears most often in a set of data. Write a function named findMode that takes as parameters an array of int and the size of the array, and returns a vector containing the mode(s). If there is just a single most frequent value, the vector will only contain that one value, but if multiple values tie for maximum frequency, the vector will need to contain all such values. This includes the case where every number in the array appears only once. Each mode should appear only once in the vector. The values in the vector that is returned must be in ascending order. If you need to sort a vector, it's similar to sorting an array, but specifying the beginning and end of the vector look a little bit different. If your vector is named result, then it would look like this: "std::sort(result.begin(), result.end());". ------------------------------------------------------- #include // needed for the sort() function #include // needed to use the vector type
  • 11. #include // needed for the main function using std::vector; using std::sort; vector findMode(int array[], int size) { int maxFreq = 1; // initalizing the largest frequency to be 1 vector result; // results is an empty vector //Initializing the loop through the integer array
  • 12. for (int i = 0; i < size; i++) { int count = 1; //started the counter at 1 //started the the loop after the 1st entry, looking for matches with the value at index i. for (int j = i + 1; j < size; j++) { //if an entry matches another, then add one to the counter if (array[i] == array[j]) { count++; }
  • 13. } //when the counter is equal to the max frequency, the integer is added to the result vector. if (count == maxFreq) { result.push_back(array[i]); } //when the counter for i is greater than the max frequency, updates the maxFreq, clear the values stored in the result vector, and push the value to the empty vector. if (count > maxFreq) { maxFreq = count;
  • 14. result.clear(); result.push_back(array[i]); } } //sort the modes in ascending order sort(result.begin(), result.end()); return result; Solution Here is your main method, Copy Paste This code and Replace your main method using the below Code. int main() { //Case 1 // int arr[10]= {1,1,1,1,1,1,1,2,3,4}; //vector result = findMode(arr,10); //Case 2
  • 15. // int arr[10]= {1,2,3,4}; //vector result = findMode(arr,4); //Case 3 // int arr[1]= {1}; //vector result = findMode(arr,1); //Case 4 // int arr[10]= {1,1,2,2,3,3}; //vector result = findMode(arr,6); int arr[10]= {1,1,2,2,3,3}; vector result = findMode(arr,6); for (std::vector::iterator it = result.begin() ; it != result.end(); ++it) std::cout << ' ' << *it; } I have written few more Tests for you, you can uncomment them and test your code using those inputs. I hope it helps.