Question

As described in the function prototype comment, this function takes two arguments, a single-dimension character array...

As described in the function prototype comment, this function takes two arguments, a single-dimension character array of scores (E/M/R/N) and an integer designating the size of the array, and returns an integer indicating the next homework number (zero-based) the student should submit. If any score is 'R' or 'N', then the index of the first such score is returned. Next, if any score is an 'M', then the index of the first such score is returned. Finally, if all the scores are 'E's (which will be the case if neither of the previous conditions is satisfied), then return a -1 indicating that no assignments need to be redone.

Note that you will need to make two passes over the provided scores, first looking for 'R' or 'N', and next looking for 'M'. As you consider your loops (in this function and others), ask yourself which type of loop is best suited for the situation (for, while, or do-while).

To test each homework score you will need some form of branching. As you work on this function note that there are three ways it can return, one for an 'R' or 'N', one for an 'M', and one for all 'E's.

code:

// Function: getNextResubmission // Precondition: homeworkScores is an array of length size

// Postcondition: Returns the homework number the student should resubmit.

// The suggested homework should be the first homework assignment

// that the student scored a R or N. // If all homework has an M or E, then the suggested homework

// should be the first M. // If the student has all E's, then return -1.

int getNextResubmission(char homeworkScores[], int size){ }

/*====================================================================

* Main program */

int main() {

// define an array for student names

string names[CLASS_SIZE] = {"Ava", "Brook", "Caryon", "Daniel", "Emma", "Perfect"};

// define an array for student ids

long ids[CLASS_SIZE] = {142001, 142002, 142003, 142004, 142005, 777777};

// define a 2D array of scores char homeworkScores[CLASS_SIZE][NUMBER_OF_SCORES] = {

{'E', 'E', 'E', 'E', 'M', 'N', 'E', 'R', 'E', 'M', 'N', 'R', 'R', 'N'},

{'M', 'M', 'E', 'M', 'M', 'R', 'R', 'M', 'R', 'N', 'N', 'N', 'N', 'N'},

{'E', 'E', 'E', 'E', 'M', 'E', 'E', 'M', 'E', 'E', 'E', 'M', 'E', 'E'},

{'E', 'E', 'M', 'N', 'R', 'R', 'M', 'E', 'M', 'M', 'M', 'M', 'E', 'E'},

{'E', 'E', 'M', 'E', 'M', 'M', 'E', 'M', 'E', 'E', 'E', 'M', 'E', 'E'},

{'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E'}, };

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int getNextResubmission(char homeworkScores[],int size)

{

int i,j,n;

for(i=0;i<=size;i++)

{

for(j=0;j<=i;j++)

{

if(homeworkScores[i][j]=='R' || homeworkScores[i][j]=='N')

{

n=j;

printf("%d",n);

}

else if(homeworkScores[i][j]=='M')

{

n=j;

printf("%d",n)

}

else

printf("-1");

}

}

}

int main()

{

string names[CLASS_SIZE]={"AVA","BROOK","CARYON","DANIEL","EMMA","PERFECT"};

long ids[CLASS_SIZE]={142001,142002,142003,142004,142005,777777};

char homeworkScores[CLASS_SIZE][NUMBER_OF_SCORES]={

{'E','E','E','E','M','N','E','R','E','M','N','R','R','N'},

{'M','M','E','M','M','R','R','M','R','N','N','N','N','N'},

{'E','E','E','E','M','E','E','M','E','E','E','M','E','E'},

{'E','E','M','N','R','R','M','E','M','M','M','M','E','E'},

{'E','E','M','E','M','M','E','M','E','E','E','M','E','E'},

{'E','E','E','E','E','E','E','E','E','E','E','E','E','E'}};

}

Add a comment
Know the answer?
Add Answer to:
As described in the function prototype comment, this function takes two arguments, a single-dimension character array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the r...

    C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything.     Your function should be named...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • In this project, the students will finish three functions that are described in Programming Project 4...

    In this project, the students will finish three functions that are described in Programming Project 4 (on page 536) and Programming Project 6 (on page 358). The student will also implement the main function and a print function to test these three functions. Please notice, there is a video notes for the solution of Project 6. However, your main function shall have more test than what in video notes. The student may start with the attached code. Please rename the...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Hello, I am having trouble with a problem in my C language class. I am trying...

    Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct {     char name[MAX_SIZE1];     int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...

  • A function that takes three parameters: an int array, an int n that is the size...

    A function that takes three parameters: an int array, an int n that is the size of the array and an int pointer max that is to assign the maximum value in the array. The function will find and return the index of the first occurrence of the maximum value in the array and assign the maximum value to the pointer. For example, in the array {1, 2, 6, 5, 6, 4, 3, 6, 4}, the maximum value is 6...

  • 1. The following program calls the function countLarger that accepts three arguments: an integer array, an...

    1. The following program calls the function countLarger that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n. The function countLarger should return the number of integers in the array that are greater than the value of the argument n. Update the program to include the definition of the function countLarger. #include <iostream> using namespace std; int countLarger(int[], int, int); // Function prototype int main() const int...

  • I wrote a program that takes a person's name and their 10 quiz scores from an...

    I wrote a program that takes a person's name and their 10 quiz scores from an input file and then prints it to an output file in a slightly different format that also has the average of their quiz scores. Here is an example INPUT Mike Johnson 100 45 68 99 34 66 88 99 88 66 OUTPUT Student Name Quiz Scores Average Johnson, Mike 100 45 68 99 34 66 88 99 88 66 75.30 It works fine when...

  • C++ Please     Contact list - functions & parallel arrays/CStrings No Vectors can be used since we...

    C++ Please     Contact list - functions & parallel arrays/CStrings No Vectors can be used since we haven't learned them yet !! A contact list is a place where you can store a specific information with other associated information such as a phone number, email address, birthday, etc. Write a program that will read 5 data pairs into two parallel arrays. Data pairs consist of a name (as a CString) and a GPA (double). That list is followed by a name,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT