Write a C++ program named "leapyear.cpp". This program reads the year values from a data file and determines wherhter th

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a C++ program named "leapyear.cpp". This program reads the year values from a data file and determines wherhter th

Post by answerhappygod »

Write a C++ program named "leapyear.cpp". This programreads the year values from a data file and determines wherhter theyear is leap year or not. The data file can be copied into yourclosed lab directory with the following command:
cp ~cen/data/years.dat . <--notice the trailing period
The data file contains year values, one value per line. Here isan example of the data:
1984 1345 2004 2015 1800 2021 1900 2000 2020 Your program readsin one year value, determines whether it is a leap year, output theresult, and move on to process the next year value. Keep doing thisuntil the end of the data file is reached.
An example program output for this data file is shown below:
yes no yes no no no no yes yes
Use a while loop to process the year values one by one til theend of the data file :
// this while loop will read the year value one at a time tilthe end of the data file is reached while (cin >> year) { //add code to process the year value here }
Use input redirect to allow the program to read from the datafile supplied from the Linux command line. Run the program with theinput redirect command as the following:
a.out < years.data
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply