Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description The purpose of this challenge is to write files. This challenge creates a pseudo time card from user input, arrays and character arrays to

Description

The purpose of this challenge is to write files. This challenge creates a pseudo time card from user input, arrays and character arrays to format data.

Requirements

Create an array of doubles to contain 5 values

Prompt the user to enter 5 values that will be stored in the array. These values represent hours worked. Each element represents one day of work.

Create 3 c-strings: full[40], first[20], last[20]

Create a function parse_name(char full[], char first[], char last[]). This function will take a full name such as Noah Zark and separate Noah into the first c-string, and Zark into the last c-string.

Create a function void create_timecard(double hours[], char first[], char last[]). This function will create (write to) a file called timecard.txt. The file will contain the parsed first and last name, the hours, and a total of the hours. See the final file below.

First Name: Noah Last Name: Zark Day 1 : 8.0 Day 2 : 8.5 Day 3 : 8.0 Day 4 : 8.5 Day 5 : 8.0 Total : 41.0 

In main, you will prompt the user to enter full name only. The parse_name() function will be used to parse full name into first and last.

Dont forget to close your files in your functions. You may create as many functions as you need in addition to the ones outlined above. Try to keep your main() function clean and get in the habit of separating functionality into separate functions that perform lean tasks.

Hint

void parse_name(char full[], char first[], char last[]) { // to get this function working immediately, first // stub it out as below. When you have everything else // working, come back and really parse full name // this always sets first name to "Noah" strcpy(first, "Noah"); // this always sets last name to "Zark" strcpy(last, "Zark"); // replace the above calls with the actual logic to separate // full into two distinct pieces } 

Sample main()

int main() { char full[40], first[20], last[20]; double hours[5]; // ask the user to enter full name // parse the full name into first and last // load the hours // create the time card return 0; } 

Sample Interaction / Output

What is your name? John Doe Enter hours for day 1: 8.0 Enter hours for day 2: 8.5 Enter hours for day 3: 8.0 Enter hours for day 4: 8.5 Enter hours for day 5: 8.0 Timecard is ready. See timecard.txt 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions