Asked by riley
a student designed a program to accept the age of an employee and then compute the employees retirement year and display the same in a statement on the screen required.
a) write out the pseudo-code for the program above
b) write the algorithm,
c) flowchart
d) write the program in c
a) write out the pseudo-code for the program above
b) write the algorithm,
c) flowchart
d) write the program in c
Answers
Answered by
Matt
string[] dDate = dob.Split('/');
string dDay = dDate[0];
string dMonth = dDate[1];
string dYear = dDate[2];
if (Convert.ToInt32(dDay) > 01)
{
if (Convert.ToInt32(dMonth) == 01 || Convert.ToInt32(dMonth) == 03 || Convert.ToInt32(dMonth) == 05 || Convert.ToInt32(dMonth) == 07 || Convert.ToInt32(dMonth) == 08 || Convert.ToInt32(dMonth) == 10 || Convert.ToInt32(dMonth) == 12)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 31;
}
else if (Convert.ToInt32(dMonth) == 04 || Convert.ToInt32(dMonth) == 06 || Convert.ToInt32(dMonth) == 09 || Convert.ToInt32(dMonth) == 11)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 30;
}
else if (Convert.ToInt32(dMonth) == 02)
{
if ((Convert.ToInt32(dYear) % 4) == 0)
{
if ((Convert.ToInt32(dYear) % 100) == 0)
{
if ((Convert.ToInt32(dYear) % 400) == 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 29;
}
if ((Convert.ToInt32(dYear) % 400) != 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 28;
}
}
if ((Convert.ToInt32(dYear) % 100) != 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 29;
}
}
if ((Convert.ToInt32(dYear) % 4) != 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 28;
}
}
//like wise we can do for month 01 but here retirement month will be minus 1 from curretnt month
string dDay = dDate[0];
string dMonth = dDate[1];
string dYear = dDate[2];
if (Convert.ToInt32(dDay) > 01)
{
if (Convert.ToInt32(dMonth) == 01 || Convert.ToInt32(dMonth) == 03 || Convert.ToInt32(dMonth) == 05 || Convert.ToInt32(dMonth) == 07 || Convert.ToInt32(dMonth) == 08 || Convert.ToInt32(dMonth) == 10 || Convert.ToInt32(dMonth) == 12)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 31;
}
else if (Convert.ToInt32(dMonth) == 04 || Convert.ToInt32(dMonth) == 06 || Convert.ToInt32(dMonth) == 09 || Convert.ToInt32(dMonth) == 11)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 30;
}
else if (Convert.ToInt32(dMonth) == 02)
{
if ((Convert.ToInt32(dYear) % 4) == 0)
{
if ((Convert.ToInt32(dYear) % 100) == 0)
{
if ((Convert.ToInt32(dYear) % 400) == 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 29;
}
if ((Convert.ToInt32(dYear) % 400) != 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 28;
}
}
if ((Convert.ToInt32(dYear) % 100) != 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 29;
}
}
if ((Convert.ToInt32(dYear) % 4) != 0)
{
RYear = Convert.ToInt32(dYear) + 60;
RMonth = Convert.ToInt32(dMonth);
RDay = 28;
}
}
//like wise we can do for month 01 but here retirement month will be minus 1 from curretnt month
Answered by
Steve
wow. Things would have been have been a lot more compact if you had used an array of month days:
modays[12] = [0,31,28,31,30,...]
and then just adjusted the 28 as needed for the leap year.
modays[12] = [0,31,28,31,30,...]
and then just adjusted the 28 as needed for the leap year.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.