In pseudocode Design an application in which the number of days for each month i
ID: 3566209 • Letter: I
Question
In pseudocode Design an application in which the number of days for each month in the year is stored in an array. (For example, January has 31 days, February has 28, and so on. Assume that the year is not a leap year.) Prompt a user to enter a birth month and day, and continue to prompt until the day entered is in range for the month. Compute the day's numeric position in the year. (For example, February 2 is day 33.) Then, using parallel arrays, find and display the traditional Zodiac sign for the date. For example, the sign for February2 is Aquarius.
Explanation / Answer
//Create an array month which contains the no of days in month
int mn[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
//Ask the user to input the date
do
{
d = Input("Enter day")
m = Input("Enter month")
}
while(d>=mn[m] && d<= mn[m]);
//The While condition makes sure that the date is proper
//Do-while is used because first the input is taken and then the check is made
//Next task is to calculate day no
//day_no = no of days in month before the input month + day no in input month
int day_no = 0;
for(i=0;i<m;i++)
{
day_no += mn[i];
}
day_no = day_no + d;
//Next job is to find zodiac sign
//In each month , there can be maximum of 2 zodiac signs, exploit this fact
//declare an array zodaic that coressponds to 2 components
//first is the transition point, like Apr 20 is Aries and April 21 is Tauras
//So Transition point is 20 for April , TP[4] = 20 ; 4 is index of month April
//Another Parallel String Array that maps the 2 signs , ZOD1[4] = "Aries" and ZOD2 = "Tauras"
//So if the date is 15-04 then, find TP , if(d<TP) print ZOD1[m] else ZOD2[m]
int TP[13] = {...20,21,.....Fill these....}
String ZOD1[13] = {"Capricorn", "Aquarius",....}
String ZOD2[13] = {"Aquarius", "Pieces",.....}
trans = TP[m];
if(d<=tans)
print ZOD1[m];
esle
print ZOD2[m];