Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write in C++ program. The header, implementation and driver files should be resp

ID: 3603824 • Letter: W

Question

Write in C++ program. The header, implementation and driver files should be respectively named : Calendar.h,
Calendar.cpp and TestCalendar.cpp. Please post a picture of sample output for a proof that it works.

Develop in C+ operations a class date to represent a calendar. The class should provide the following » A default constructor that initializes a date obiect to 01-01-1900 . A class constructor that initializes a date object to a correct value using three integer parameters corresponding to the desired month, day and year » The function toString() that returns the string version of a date object. For example, applying toString() to the date 12-01-2000 produces "December 1st, 2000". » The function nextDate () that returns the successive date i.e. the new value of the date object. For example, applying nextDate) to the date 12-31-2000 produces a new date: 01-01-2001. You should take into account if the year is a leap year or not. A leap year is: (1) divisible by 400 or (2) divisible by 4 and not divisible by 100 » The function compareDates ) that checks if the date of interest is before, after or equal to the argument date. A simple run of the driver program follows 12-32-2000 Enter the first date using the format mm-dd-yyyy: Incorrect day! Enter the first date using the format mm-dd-yyyy: The string version of the date is: December 31st, 2000 The next date in string version is: January 1st, 2001 Enter the second date using the format mm-dd- The first date comes before the second one 12-31-2000 yyyy: 12-01-2001 Another run: Enter the first date using the format mm-dd-yyyy: The string version of the date is: February 28th, 2005 The next date in string version is: March 1st, 2005 Enter the second date using the format mm-dd-yyyy: The first date comes after the second one 02-28-2005 01-10-2005

Explanation / Answer

import java.util.Scanner;

import java.io.File;
import java.io.FileNotFoundException;

public class SemiMagic {

public static boolean isFullSolution(int[][] square) {
// TODO: Complete this method
return false;
}

public static boolean reject(int[][] square) {
// TODO: Complete this method
return false;
}

public static int[][] extend(int[][] square) {
// TODO: Complete this method
return null;
}

public static int[][] next(int[][] square) {
// TODO: Complete this method
return null;
}

static void testIsFullSolution() {
// TODO: Complete this method
}

static void testReject() {
// TODO: Complete this method
}

static void testExtend() {
// TODO: Complete this method
}

static void testNext() {
// TODO: Complete this method
}

/**
* Returns a string representation of a number, padded with enough zeros to
* align properly for the current size square.
* @param num the number to pad
* @param size the size of the square that we are padding to
* @return the padded string of num
*/
static String pad(int num, int size) {
// Determine the max value for a square of this size
int max = size * size;
// Determine the length of the max value
int width = Integer.toString(max).length();
// Convert num to string
String result = Integer.toString(num);
// Pad string with 0s to the desired length
while (result.length() < width) {
result = " " + result;
}
return result;
}

/**
* Prints a square
* @param square the square to print
*/
public static void printSquare(int[][] square) {
if (square == null) {
System.out.println("Null (no solution)");
return;
}
int size = square.length;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
System.out.print(pad(square[i][j], size) + " ");
}
System.out.print(" ");
}
}

/**
* Reads a square of a specified size from a plaintext file
* @param filename the name of the file to read from
* @param size the size of the square in the file
* @return the square
* @throws FileNotFoundException if the named file is not found
*/
public static int[][] readSquare(String filename, int size)
throws FileNotFoundException {
Scanner scanner = new Scanner(new File(filename));
int[][] square = new int[size][size];
int val = 0;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
square[i][j] = scanner.nextInt();
}
}
return square;
}

/**
* Solves the magic square
* @param square the partial solution
* @return the solution, or null if none
*/
public static int[][] solve(int[][] square) {
if (reject(square)) return null;
if (isFullSolution(square)) return square;
int[][] attempt = extend(square);
while (attempt != null) {
int[][] solution;
solution = solve(attempt);
if (solution != null) return solution;
attempt = next(attempt);
}
return null;
}

public static void main(String[] args) {
if (args.length >= 1 && args[0].equals("-t")) {
System.out.println("Running tests...");
testIsFullSolution();
testReject();
testExtend();
testNext();
} else if (args.length >= 1) {
try {
// First get the specified size
int size = Integer.parseInt(args[0]);

int[][] square;
if (args.length >= 2) {
// Read the square from the file
square = readSquare(args[1], size);
} else {
// Initialize to a blank square
square = new int[size][size];
}

System.out.println("Initial square:");
printSquare(square);

System.out.println(" Solution:");
int[][] result = solve(square);
printSquare(result);
} catch (NumberFormatException e) {
// This happens if the first argument isn't an int
System.err.println("First argument must be the size");
} catch (FileNotFoundException e) {
// This happens if the second argument isn't an existing file
System.err.println("File " + args[1] + " not found");
}
} else {
System.err.println("See usage in assignment description");
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote