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

Problem Statement: Design a C++ program that will allow the user to select from

ID: 3767813 • Letter: P

Question

Problem Statement:

Design a C++ program that will allow the user to select from the following :

Main Menu

[1] Fibonacci Series Nth Term

[2] Number of Days in a Given Month

[3] Block Letter N

[4] Exit

1. Fibonacci Series Nth Term

Fibonacci numbers was invented by Leonardo of Pisa (Fibonacci). He defined fibonacci numbers as a growing population of immortal rabbits. Series of Fibonacci numbers are: 1,1,2,3,5,8,13,21,...

The Fibonacci sequence is 0,1,1,2,3,5,8,13,… where the first two terms are 0 and 1, and each term thereafter is the sum of the two preceding terms.

The Nth term in the Fibonacci number series can be evaluated using the formula:

Fn        1     1 +   5   N       1 -   5    N

          5         2                   2

-

=

Design a program that accepts N and displays Fn. Note that the result of computation using the (math.h /cmath) class is double. You need to display it as an integer.

Sample Run:

Input value of N : 8

The 8(st/nd/rd/th) Term in the Fibonacci number series is : 21

2. Number of Days in a Given Month

Design a program that will input month (1-12) and year represented by an integer number (1-12).

January(1), March(3), May(5), July(7), August(8), October(10), December(12) = 31 days

April(4), June(6), September(9), November(11) = 30 days

For Leap year February(2) = 29 days

Not leap year February(2) = 28 days    

3. Block Letter N. Input the size of letter N and display the block form of letter N. Validate the input such that the minimum size should be 4 to form the block form of letter N. This example output has a size of 5.

Input the size of Letter N: 5

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

N

Fn        1     1 +   5   N       1 -   5    N

          5         2                   2

Explanation / Answer

#include <iostream.h>
int fibo(int);
int no_month(int month);
void letter_N(int n);

int main()
{
   int num, result, month, numberOfDays, n,ch;
  
   while(1)
   {
       cout<<"[1] Fibonacci Series Nth Term [2] Number of Days in a Given Month [3] Block Letter N [4] Exit";
       cout<<"ENter Your choice : ";
       cin>>ch;

       switch(ch)
       {
           case 1:      
               cout<<"Enter the nth number in fibonacci series: ";
               cin>>num;
               if (num < 0)
               {
               cout<<"Fibonacci of negative number is not possible. ";
               }
               else
               {
               result = fibo(num);
               cout<<"The"<<num<<" number in fibonacci series is "<<result;
                }
               break;
           case 2:
               cout<<"Enter the number number [1 - 12] : ";
               cin>>month;
               numberOfDays=no_month(month);
               cout<<"The Number of Days : "<<numberOfDays;
               break;
           case 3:
               cout<<"Enter the size of the letter N : ";
               cin>>n;
               letter_N(n)
               break;

           case 4:
               exit(0);
       }
   }
              
   return 0;
}
int fibo(int num)
{
if (num == 0)
{
return 0;
}
else if (num == 1)
{
return 1;
}
else
{
return(fibo(num - 1) + fibo(num - 2));
}
}
int no_month(int month)
{
   int numberOfDays;
   if (month == 4 || month == 6 || month == 9 || month == 11)
       numberOfDays = 30;
   else if (month == 2)
   {
       bool isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

       if (isLeapYear)
           numberOfDays = 29;
       else
           numberOfDays = 28;
   }
   else
        numberOfDays = 31;
   return(numberOfDays);
}
void letter_N(int n)
{
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<1;j++)  
           cout<<"N";
       for(int j=0;j<n;j++)
       {
           if(i==j)
               cout<<"N";
          
       }
       for(int j=n-1;j>n;j--)
           cout<<"N";
   }
}

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