C++

I am primary school student and I don't know much about programming. Please help me with my homework.... Thanks advance for your help.. below is the codes and comments where necessary codes will be applied..

The program should consist of the following functions.Add appropriate codes in the provided comments and other
additional code not provided that makes your program work.
*/

// include standard input output header
// include string header
// constant MaxCandidate set to 7 to represent the maximum number of candidates
//constant MaximumNameLength to represent the maximum name (first name + last name) length
// Pointers to input and output file

#include<ctype.h>
#include<stdio.h>
#include<string>
#include<iostream>
#define MaxCandidate 7
#define MaximumNameLength (first name + last name)
#include<pointer>


int main(){

// declare two dimensional array called name to hold first name and last name
char name[][];


// the name first dimension should be the size of MaxCandidate +1
int firstDimension[7 + 1];

// the name second dimension should be the size of MaxNameLength + 1
int secondDimension[50 + 1];


//declare single dimensional array called vote to hold number of votes for each candidate


//declare variable v to hold the number of votes
int v;

//declare variable validVotes and initialise to 0
int validVoteds = 0;

//declare variable spoiltVotes and initialise to 0
int spoiltVotes = 0;


// function prototype for function initialise
void initialise(int);

//function prototype for function printResults
void printResults(int);

//open votes.txt file for reading data from
FILE * in = fopen("votes.txt", "r");

//open results.txt file for writing data to
FILE * in = fopen("results.txt", "w");

// function initialise call
initialise();

// read data from votes.txt file and assign them to place them in the memory location for variable v
while (v != 0)
{
if (v < 1 || v > MaxCandidates)
{
//print invalid vote and a number of invalid votes
printf("These are invalid votes:");

//increment spoilt votes
count = count + 1;

}
else
{
// increment the vote
count = votes + 1;

//increment valid votes
count = validVotes + 1;

}
//read data from votes.txt file

}
//function printResults call
// close electionVotes.txt file
// close electionResults.txt file
}
void initialise(char name[][MaxNameLength + 1], int vote[])
{
char lastName[MaxNameLength];
for (int c = 1; c <= MaxCandidates; c++)
{
// read first name and last name from the candidates text file
// creates a space between the name (between first name and last name
//concatenates first name and last name
}
}
//end function initialise
int getLargest(int num[], int lo, int hi)
{
// declare variable big of type int and assign variable lo to it
for (int h = lo + 1; h <= hi; h++)
{
if (num[h] > num[big])
{
big = h;
}
}
// return big
}
// end function getLargest
void printResults(char name[][MaxNameLength + 1], int vote[], int valid, int spoilt)
{
// function prototype for getLargest function
// print to results.txt number of total voters which is equal to valid votes + spoilt votes
// print to results.txt the number of valid votes

// print to results.txt the number of spoilt votes

// Headings with tab spacing in results.txt file
for (int c = 1; c <= MaxCandidates; c++)

//print to results.txt the names and votes separated by a tab spacing
// print to results.txt the text "The winner(s)
// call getLargest function and assign it to int win variable
//assign vote = to winningVote
for (int c = 1; c <= MaxCandidates; c++)
if (vote[c] == winningVote)
// print to results.txt, the names
}
// end function printResults
Last edited on
Line 7: Correct header is <cctype>
Line 8: Correct header is <cstdio>

Line 12: first name and last name are undefined. first name and last name need _ between the parts.

Line 13: What is header <pointer> ?

Line 18: The dimensions of name[][] are not defined.

Line 43,46: Function prototypes should be before main().

Line 49.52: You have two file pointers named in.

Line 55: You declared initialise() to require an int arguemnt, but you're not passing an argument.

Line 60: MaxCandidates is undefiined. #define at line 11 is singular.

Line 66,72: count is undefined.

Line 72: votes is undefined.

Line 75: validVotes is undefined. Misspelling at line 36?

Line 85: MaxNameLength is undefined. Did you mean MaximumNameLength ?

Line 101,103: big is undefined.

Line 107: getLargest() doesn't return anything.

Line 126: There is no conditional statement under the if.

Your compiler should have pointed out all these errors to you. Pay attention to the errors reported by the compiler. Sometimes it is best to fix the first error, recompile, then more on to the next error.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Hello kunarakra,

AbstractionAnon has pointed out problems with your code. I thought these links would be of some use:

Arrays:
http://www.cplusplus.com/doc/tutorial/arrays/
http://www.cplusplus.com/search.do?q=c+style+array ** A search page **

Functions:
http://www.cplusplus.com/doc/tutorial/functions/

When you define
// the name first dimension should be the size of MaxCandidate +1
int firstDimension[7 + 1];

All you really need is int firstDimension[MaxCandidate]. The + 1 is not needed.

That can get you started.

Hope tht helps,

Andy
Last edited on
Topic archived. No new replies allowed.