C++代写:CS101 Write A Program

基础的C++编程,完成一个日期转换器。

Data convert

Purpose

To practise and assess everything up to and including selection.

Learning outcome/s being assessed

  • storage, manipulation, input, and output of simple data types
  • selection (ifs and related features of C++)

Task

Write a program, run it, and test that it is performing correctly for all cases.

Instructions

Test widely, especially cases that are not simple.

Marking criteria

Marked out of 10 and marks can be lost for:

  • programs not compiling or running
  • errors in code
  • failure to use, or show a good appreciation of, concepts being assessed
  • programs that have not been tested widely
  • use of features of C++ not yet taught, unless explained to the tutor’s satisfaction
  • plagiarism (from other students past or present, or from anything online)
  • violations of the indentation rules
  • any program that appears copied or written by another person, will be awarded a temporary mark of 0. To change the mark, the student must explain their program line by line to the tutor, showing a full understanding of the submission.

Put your name and ID number in a comment at the top of your program.
Refer to the notes up to and including section 2.

Write a C++ program that does the following

  • a) input a number of days from -7 to 7. This value is called thedifference.
  • b) input a date as day month year
  • c) display the date that isdifferentdays from the input date

Example 1

Enter the difference in days: 2
Enter a date in the form day month year: 14 5 2019
The final date is: 16/5/2019

Example 2:

Enter the difference in days: -3
Enter a date in the form day month year: 8 11 2020
The final date is: 5/11/2020

Example 3:

Enter the difference in days: 1
Enter a date in the form day month year: 31 12 2017
The final date is: 1/1/2018

Notes

  1. Your display should be similar to the examples above.
  2. Assume that the date that is entered is a valid date (no need to check).
  3. Assume that the difference that is entered is from -7 to 7 (no need to check).
  4. You will need to check if the year is a leap year.
  5. Remember to test your program with several different examples.

A possible approach

  1. Get the program working for positive differences and ignore February.
  2. Modify the program to also work for negative differences and continue to ignore February.
  3. Modify the program to include February.