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
Write a C++ program named "leapyear.cpp". This program reads the year values from a data file and determines wherhter th
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am