I added the deleteMarks function and now it will not compile, please help! #incl
ID: 3626432 • Letter: I
Question
I added the deleteMarks function and now it will not compile, please help!#include <iostream>
#include <iomanip>
using namespace std;
bool addMark(double *allMarks, int &totalRec, double &mark);
bool displayMarks(double allMarks[], int totalRec);
bool findMean(double allMarks[], int totalRec, double &mean);
void deleteMarks(double allMarks[],int &totalRec);
int numOfOccur(double allMarks[],int totalRec,int markToSearch);
void printOccurances(double allMarks[],int totalRec);
int main() {
char ch='y';
double mark=0.0;
int option=0;
double mean =0.0;
int totalRec = 0;
double allMarks[1000];
do
{
cout << " MAIN MENU
0. Exit
1. Add a student mark
2. List all student marks
3. Calculate the marks average
4. Calculate the standard deviation
5. Delete a student mark
6. Find the number of students via a mark
7. Display distinct marks and their occurrences
Your choice -> ";
cin>>option;
switch(option)
{
case 0:
exit(1);
break;
case 1:{
cout<<"Enter mark to add"<<endl;
cin>>mark;
if(mark > 100 || mark < 0)
cout<<"Invalid entry"<<endl;
else
{
if(addMark(allMarks,totalRec,mark))
cout<<"Entry added"<<endl;
else
cout<<"Entry not added"<<endl;
}
break;
}
case 2:{
if(displayMarks(allMarks,totalRec))
;
else
cout<<"No elements added yet";
break;
}
case 3:{
if(findMean(allMarks,totalRec,mean))
;
else
cout<<"No elements added yet";
break;
}
case 4: break;
case 5: deleteMarks(allMarks,totalRec);break;
case 6:{
cout<<" Enter the element to find occurances"<<endl;
int markToSearch=0;
cin>>markToSearch;
cout<<"The mark "<<markToSearch<<" occured "
<< numOfOccur(allMarks,totalRec,markToSearch)
<<" times"<<endl;
break;
}
case 7:{
cout<<endl;
printOccurances(allMarks,totalRec);
cout<<endl;
break;
}
case 8:{
exit(1);
break;
}
}
} while(1);
system("PAUSE");
}
bool addMark(double *allMarks, int &totalRec, double &mark)
{
if(mark <=100){
allMarks[totalRec] = mark;
totalRec++;
return true;
}
else
return false;
}
bool displayMarks(double allMarks[], int totalRec)
{
if(totalRec>0){
int i =0;
cout<<"Marks in the list are: ";
while(i < totalRec){
cout<<allMarks[i]<<" ";
i++;
}
cout<<endl;
return true;
}
else
return false;
}
bool findMean(double allMarks[], int totalRec, double &mean)
{
if(totalRec>0){
int i =0;
double total = 0.0;
while(i < totalRec)
{
total += allMarks[i];
i++;
}
mean = total/totalRec;
cout<<" Average is "<<std::fixed<<setprecision(5)<<mean<<endl;
return true;
}
else
return false;
}
void deleteMarks(int marks[],int &totalRec)
{
int value;
cout<<"Enter marks to be delete: ";
cin>>value;
int flag=false;
for(int i=0;i<totalRec;i++)
if(marks[i]==value)
{
for(int j=i+1;j<totalRec;j++)
marks[j-1]=marks[j];
flag=true;
totalRec--;
break;
}
if(flag)
cout<<" Successfully deleted"<<endl;
else
cout<<" Not found in the list"<<endl;
}
int numOfOccur(double allMarks[],int totalRec,int markToSearch)
{
int cnt =0;
int i =0;
while(i < totalRec)
{
allMarks[i]==markToSearch ? cnt++ : false;
i++;
}
return cnt;
}
void printOccurances(double allMarks[],int totalRec)
{
int *occur = new int[101];
int i = 0;
int ind =-1;
for(int j=0;j<101;j++)
{
occur[j]=0;
}
while(i < totalRec)
{
ind = (allMarks[i]);
occur[ind]++;
i++;
}
cout<<"MARKS OCCURRENCES"<<endl;
cout<<"----------------------"<<endl;
for(int j=0;j<101;j++)
{
if(occur[j]>0)
cout<<j<<" "<<occur[j]<<endl;
}
}
Explanation / Answer
The problem that i see is that you have the two headers differing, which is throwing an error, in the header you have:
void deleteMarks(double allMarks[],int &totalRec);
however in the actual program you have:
void deleteMarks(int allMarks[],int &totalRec)
So if you simply change this it will compile and work fine
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.