Please show all output for program and test 1 Please write t
Please show all output for program and test.
1. Please write the following in C++ also please show all output code and comment on code.
2. Also, use CPPUnitLite to write all test and show outputs for each test.
Write CppUnitLite tests to verify correct behavior for all the exercises. The modifications are aimed at making the exercises more conducive to unit tests.
Write a function that swaps (exchanges the values of two integers). Use int* as the argument type. Write a second swap function using a reference (i.e., int&) as the argument type.
Define a table of the names of months of the year and the number of days in each month. Write out that table to a stringstream. Do this twice; once using an array of char for the names and an array for the number of days and a second time using an array of structures, with each structure holding the name of a month and the number of days in it.
Write a function cat() that takes two C-style strings (i.e., char*) arguments and returns a C-style string that is the concatenation of the arguments. Use new to find store for the result. Write a second function cat that takes two const std::string& arguments and returns a std::string that is a concatenation of the arguments. The std::string version does not require new. Which is the better approach? Explain your rationale for which is the better approach?
Solution
Function that swaps :
Output
Define a table of the names of months of the year and the number of days in each month
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main ()
{
int year,month,firstday,leapsum, days;
cout<<\"Please enter the number of the month and year to access calendar\ \"<<endl;
cout<< \"Please leave a space in between the month and year when you enter them: \ \";
cin>>month>>year;
firstday=(((year-1)*365)+4*((year-1)/4)-4*((year-1)/100)+4*((year-1)/400)+1)%7;
leapsum=(!(year%4)&&(year%100))||!(year%400);
day
system(\"cls\");
switch (month)
{case 1:
month;
{if (leapsum=0)
days=31;
else
days=31;}
cout<<\"January\"<<\" \"<<firstday<<\" \"<<year;
break;
case 2:
month;
{if (leapsum=0)
days=29;
else
days=28;}
cout<<\"February\"<<\" \"<<firstday<<\" \"<<year;
break;
case 3:
month;
{if (leapsum=0)
days=31;
else
days=31;}
cout<<\"March\"<<\" \"<<firstday<<\" \"<<year;
break;
case 4:
month;
{if (leapsum=0)
days=30;
else
days=30;}
cout<<\"April\"<<\" \"<<firstday<<\" \"<<year;
break;
case 5:
month;
{if (leapsum=0)
days=31;
else
days=31;}
cout<<\"May\"<<\" \"<<firstday<<\" \"<<year;
break;
case 6:
month;
{if (leapsum=0)
days=30;
else
days=30;}
cout<<\"June\"<<\" \"<<firstday<<\" \"<<year;
break;
case 7:
month;
{if (leapsum=0)
days=31;
else
days=31;}
cout<<\"July\"<<\" \"<<firstday<<\" \"<<year;
break;
case 8:
month;
{if (leapsum=0)
days=31;
else
days=31;}
cout<<\"August\"<<\" \"<<firstday<<\" \"<<year;
break;
case 9:
month;
{if (leapsum=0)
days=30;
else
days=30;}
cout<<\"September\"<<\" \"<<firstday<<\" \"<<year;
break;
case 10:
month;
{if (leapsum=0)
days=31;
else
days=31;}
cout<<\"October\"<<\" \"<<firstday<<\" \"<<year;
break;
case 11:
month;
{if (leapsum=0)
days=30;
else
days=30;}
cout<<\"November\"<<\" \"<<firstday<<\" \"<<year;
break;
case 12:
{if (leapsum=0)
days=31;
else
days=31;}
month;
cout<<\"December\"<<\" \"<<firstday<<\" \"<<year;
break;
default:
cout<<\"Please restart program and enter correct month and year\";
}
return 0;
}


