Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert the following program to C++: Use command-line arguments so that when you run this program, you also include the name of an input file.

Convert the following program to C++:

  1. Use command-line arguments so that when you run this program, you also include the name of an input file. For example, if your input file name is months.txt, you would type a.out theMonths.txt
    • The input file should contain the number of days and the 3 month abbreviation for all 12 months represented as a C++ string instead of a character array.
  2. Instead of declaring an array of 12 months, declare a month_t pointer and dynamically allocate enough memory to hold 12 months.
  3. Use C++ file pointers and open the input file sent in from the command-line.
  4. Create an initializeMonths() function with parameters for the months and the input file
    • Using both arguments, use a loop to read in the number of days and the month for each month from the input file.
  5. Declare a function pointer and assign it to point the printArray() function.
  6. Call the initializeMonths() function.
  7. Call the printArray() using the function pointer.
  8. Use C++ print statements and formatting of output

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx

#include

typedef struct month { int numberOfDays; char name[4]; }month_t;

void printArray(month_t monthArray[]);

int main(void) { struct month months[12] = { {31, "Jan"}, {28, "Feb"}, {31, "Mar"}, {30, "Apr"}, {31, "May"}, {30, "Jun"}, {31, "Jul"}, {31, "Aug"}, {30, "Sep"}, {31, "Oct"}, {30, "Nov"}, {31, "Dec"} }; printArray(months); return 0; } void printArray(month_t monthArray[]) { int i; printf(" "); printf("Month Number of Days "); printf("----- -------------- "); for (i=0; i<12; i++) { printf(" %s %i ", monthArray[i].name, monthArray[i].numberOfDays); } printf(" "); }

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions