Question

In: Computer Science

Hello, Modify the grade book program from Assessment 3 to use a custom struct to hold...

Hello,

Modify the grade book program from Assessment 3 to use a custom struct to hold the student's ID number and the percentage score for each item in the grade book. The program should accept the entry of ID numbers and percentage grades (0–100) until the user signals that he or she is done entering grades. The program should then print out the ID numbers and grades entered by the user, sorted by ID number. Again, be sure to format the code properly and provide comments in the C code.

Below is the program i have written, but it is not reading the date entered by the user and adding seven days to it. Instead the output is taking the the day in today's date (07/09/2020) and adding seven days to 09 and printing the date entered is whatever month I enter, but the day is always showing 16 (05/16/0000) and the new date adding seven is always showing the day of 23 (05/23/0000) and the year is always printing as zero. I would really like to understand what I have wrong in my code below please.  

#include <stdio.h>
#include <stdbool.h>

//This is a global definition of struct for date so it can be utilized for any function within the program.
struct date
{
int month;
int day;
int year;
};

//This will add the seven days to the date entered by the user
struct date newDate (struct date entered)
{
struct date week;
int daysOfMonth (struct date d);

if(entered.day != daysOfMonth(entered))
{
week.day = entered.day+=7;
week.month = entered.month;
week.year = entered.year;
}
else if(entered.month == 12)//end of month
{
week.day = 1;
week.month = entered.month = 1;
week.year = entered.year +1;
}
else //end of year
{
week.day = 1;
week.month = entered.month+1;
week.year = entered.year;
}

return week;
}

//Function to find the number of days in a month
int daysOfMonth (struct date d)
{
//Declare variables to be used within function
int days;
bool flagLeapYear (struct date d);

const int daysOfMonth [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (flagLeapYear (d) == true && d.month == 2)
days = 29;
else
days = daysOfMonth[d.month - 1];

return days;
}

//Function to determine if it is a leap year
bool flagLeapYear (struct date d)
{

bool flagLeapYear;

if ((d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0)
flagLeapYear = true; //It is a leap year
else
flagLeapYear = false; // Not a leap year

return flagLeapYear;
}


int main(void)
{
struct date newDate (struct date today);
struct date entered, seven;

printf("Please enter a date in mm/dd/yyyy format: ");
scanf(" %d%d%d", &entered.month, &entered.day, &entered.year);

seven = newDate (entered);

printf("\nThe date you entered is: %02d/%02d/%.4d", entered.month, entered.day, entered.year);
printf("\nThe date in seven days will be: %02d/%02d/%.4d", seven.month, seven.day, seven.year);

return 0;
}

Thank you,

Annette

Solutions

Expert Solution

input code:

output:

code:

#include <stdio.h>
#include <stdbool.h>

//This is a global definition of struct for date so it can be utilized for any function within the program.
struct date
{
int month;
int day;
int year;
};

//This will add the seven days to the date entered by the user
struct date newDate (struct date entered)
{
struct date week;
int daysOfMonth (struct date d);
  
/*if last month*/
if(entered.month == 12)//end of month
{
/*and value is go out of month*/
if(entered.day+7>daysOfMonth(entered))
{
/*do this*/
week.day = (entered.day+7)%(daysOfMonth(entered));
week.month = 1;
week.year = entered.year +1;
}
else
{
/*else do this*/
week.day = (entered.day+7);
week.month = entered.month;
week.year = entered.year ;
}
}
else //end of year
{
/*if day goes out of month*/
if(entered.day+7>daysOfMonth(entered))
{
/*than do this*/
week.day = (entered.day+7)%(daysOfMonth(entered));
week.month = entered.month+1;
week.year = entered.year ;
}
else
{
/*else do this*/
week.day = (entered.day+7);
week.month = entered.month;
week.year = entered.year;
}
}
  
return week;
}

//Function to find the number of days in a month
int daysOfMonth (struct date d)
{
//Declare variables to be used within function
int days;
bool flagLeapYear (struct date d);
/*declare the months value*/
const int daysOfMonth [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  
if (flagLeapYear (d) == true && d.month == 2)
days = 29;
else
days = daysOfMonth[d.month - 1];
/*return month in days*/
return days;
}

//Function to determine if it is a leap year
bool flagLeapYear (struct date d)
{
/*declare the variables*/
bool flagLeapYear;
/*check leap year or not*/
if ((d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0)
flagLeapYear = true; //It is a leap year
else
flagLeapYear = false; // Not a leap year
return flagLeapYear;
}


int main(void)
{
/*declare the struct*/
struct date newDate (struct date today);
/*declare struct variables*/
struct date entered, seven;
  
/*take user input*/
printf("Please enter a date in mm/dd/yyyy format: ");
scanf(" %d%d%d", &entered.month, &entered.day, &entered.year);
/*call method*/
seven = newDate (entered);
/*print output*/
printf("\nThe date you entered is: %02d/%02d/%.4d", entered.month, entered.day, entered.year);
printf("\nThe date in seven days will be: %02d/%02d/%.4d", seven.month, seven.day, seven.year);

return 0;
}

error:


Related Solutions

C++ tree program (do NOT use STRUCT, use classes)    Program 1 Implement a Binary tree...
C++ tree program (do NOT use STRUCT, use classes)    Program 1 Implement a Binary tree using an array    Program 2 Implement a tree using linked list - pointer Binary Tree    Program 3 - Convert program 1 to a template
In Python b) Modify your program that reads 3 grades from the user (and computes the...
In Python b) Modify your program that reads 3 grades from the user (and computes the average and letter grade) so that it uses a while loop to read the 3 grades. In the loop body, you will just read one grade and update other variables appropriately. The loop header will ensure 3 iterations. c) Modify your program in part b so that it asks the user how many grades there are and uses a while loop to read that...
4. Modify the program geometryDemo to use the class basicGeometry and the threeSides code. Note from...
4. Modify the program geometryDemo to use the class basicGeometry and the threeSides code. Note from the comments in the main routine that it wants an input argument of 3 to solve for a triangle and 4 to solve for a square or rectangle. MODIFY the code to add another method in the 'threeSides' and 'fourSides' classes to return the perimeter. ASSUME the following for TRIANGLES. ** for AREA (1/2 * base * height) dimension1 is base, dimension2 is height...
Your task is to modify the program from the Java Arrays programming assignment to use text...
Your task is to modify the program from the Java Arrays programming assignment to use text files for input and output. I suggest you save acopy of the original before modifying the software. Your modified program should: contain a for loop to read the five test score into the array from a text data file. You will need to create and save a data file for the program to use. It should have one test score on each line of...
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary...
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template (include screenshots please of output)
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary...
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template
Read inputs from console and store in Structure Given a structure of type “struct book” (shown...
Read inputs from console and store in Structure Given a structure of type “struct book” (shown below), read input into struct book from a console. struct book { char name[50]; char author[50] ; float price; }; Write a function: struct book solution() that reads name, author and price into “struct book”. A function return structure variable. Input C Programming: A Modern Approach K.N.King 50.45 where, First line of input represents book name. Second line of input represents book author. Third...
Hello, I stuck doing c++ program The program will be recieved from the user as input...
Hello, I stuck doing c++ program The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to...
Modify the AlienDirection program from this chapter so that the image is not allowed to move...
Modify the AlienDirection program from this chapter so that the image is not allowed to move out of the visible area of the window. Ignore any key that would allow this to happen. *Ask if you have any questions about the assignment I will try to clarify Textbook - JAVA FOUNDATIONS: INTRODUCTION TO PROGRAM DESIGN AND DATA STRUCTURES 5TH EDITION Starter Code Provided : import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.stage.Stage;...
Modify this program so that it takes in input from a TEXT FILE and outputs the...
Modify this program so that it takes in input from a TEXT FILE and outputs the results in a seperate OUTPUT FILE. (C programming)! Program works just need to modify it to take in input from a text file and output the results in an output file. ________________________________________________________________________________________________ #include <stdio.h> #include <string.h> // Maximum string size #define MAX_SIZE 1000 int countOccurrences(char * str, char * toSearch); int main() { char str[MAX_SIZE]; char toSearch[MAX_SIZE]; char ch; int count,len,a[26]={0},p[MAX_SIZE]={0},temp; int i,j; //Take...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT