Programming Assignment #1 Due Wednesday, September 27 th @11:59pm (via Blackboar
ID: 3884150 • Letter: P
Question
Programming Assignment #1
Due Wednesday, September 27th @11:59pm (via Blackboard)
Tomorrow’s Date (Advanced)
Similar to the In-Class Assignment regarding Tomorrow’s Date, create a program that possesses a struct named Date. This struct should possess 3 members (month, day, and year). The user should be prompted for n amount of date instances to be stored in the respective members of the struct. This program should also contain a function called nextDate() that accepts each member as an argument and updates the date to the following day’s date and prints it to the screen. Furthermore, this program should account for months that only have 30 days and February only have 28 (do not worry about leap year for this assignment).
Explanation / Answer
#include <stdio.h>
#include <time.h>
void wait ( int sec ) {
int a =0;
clock_t end_wait;
end_wait = clock () + sec * CLK_TCK;
while (clock() < end_wait) {
// Your useless calculations.
a++;
}
printf (“%i ”, a);
}
void waitspeedup ( int sec, int speedupfactor ) {
int num,a = 0;
num = sec / speedupfactor;
printf (“The new wait time is: %i ”, num);
clock_t end_wait;
end_wait = clock () + num * CLK_TCK;
while (clock() < end_wait) {
// Your useless calculations
a++;
}
// The fake result (because of speedup factor)
printf (“%i ”, a);
// Multiply result with speedupfactor to get an approximation
// of the actual results.
printf (“%i ”, a*speedupfactor);
}
int main () {
printf (“Waiting.1…. ”);
// Wait approx. 12 seconds
wait(12);
printf (“Waiting.2…. ”);
// Wait approx. 12 / 2 = 6 seconds
waitspeedup(12,2);
// There are 86400 seconds in a day
// do something like this 86400/1200=72 sec.
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.