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

I need to somehow get this completed so I can use it as a study guide for the fi

ID: 3568329 • Letter: I

Question

I need to somehow get this completed so I can use it as a study guide for the final. Any help is greatly appreciated. The language is C++

Code multiple functions.
When the program runs it should show the following menu.
You need to implement each function from the menu. A sample run is following
Enter a choice from the following menu. Make sure it is a number
###################################################################
Make a choice:
-1. I am out of here. Exit!
1. Add two octal numbers.
2. Return the number of characters in a string excluding blanks.
3. Convert a number from base 10 to another base.
4. Reverse a string of characters.
5. Display the largest and the smallest element in a list.
6. Compute the standard deviation of the elements of a list.
7. Solve a second degree equation.
8. Encode a message.
9. Decode a message.
###################################################################
2
Enter a string of characters : C++ is cool
string: C++ is cool has 9 charactersEnter a choice from the following menu. Make sure it is a number
###################################################################
Make a choice:
-1. I am out of here. Exit!
1. Add two octal numbers.
2. Return the number of characters in a string excluding blanks.
3. Convert a number from base 10 to another base.
4. Reverse a string of characters.
5. Display the largest and the smallest element in a list.
6. Compute the standard deviation of the elements of a list.
7. Solve a second degree equation.
8. Encode a message.
9. Decode a message.
###################################################################
4
Enter a string of characters to reverse : happy birthday
yadhtrib yppah
Enter a choice from the following menu. Make sure it is a number
###################################################################
Make a choice:
-1. I am out of here. Exit!
1. Add two octal numbers.
2. Return the number of characters in a string excluding blanks.
3. Convert a number from base 10 to another base.
4. Reverse a string of characters.
5. Display the largest and the smallest element in a list.
6. Compute the standard deviation of the elements of a list.
7. Solve a second degree equation.
8. Encode a message.9. Decode a message.

Explanation / Answer

C++ Program:

// jdjd.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <vector>
using namespace std;
void addOctalNumbers();
void characterCount();
void convertBase(int num, int b);
void reverseString();
void displayLargeandSmall();
void standardDeviation();
void secondDegreeEquation();
void encode(char[] st,int key);
void decode(char[] st,int key);

int main()
{
    menu();
    system("PAUSE");
    return 0;
}

void menu()
{
    int choice = 0, number = 0, spot = 0,key;
char str[20];
    while (choice != -1) {
    cout << endl;
    cout << "Enter a choice from the following menu. Make sure it is a number" << endl;
cout<<"###################################################################"<<endl;
cout<<"Make a choice:"<<endl;
    cout << "-1. I am out of here. Exit!" << endl;
    cout << "1. Add two octal numbers." << endl;
    cout << "2. Return the number of characters in a string excluding blanks." << endl;
    cout << "3. Convert a number from base 10 to another base." << endl;
    cout << "4. Reverse a string of characters." << endl;
    cout << "5. Display the largest and the smallest element in a list." << endl;
cout << "6. Compute the standard deviation of the elements of a list." << endl;
    cout << "7. Solve a second degree equation." << endl;
cout << "8. Encode a message." << endl;
    cout << "9. Decode a message." << endl;
cout<<"###################################################################"<<endl;
    cin >> choice;
    switch(choice)
    {       
       case 1:
            addOctalNumbers();
            break;
       case 2:
      characterCount();          
            break;       
       case 3:
      cout<<" Enter the Number and Base"<<endl;
   int num,b;
   cin>>num;
   cin>>b;
            convertBase(num,b);
            break;         
       case 4:
      reverseString();
            break;
    case 5:
           displayLargeandSmall();
            break;
       case 6:
      standardDeviation();          
            break;       
       case 7:
            secondDegreeEquation();
            break;         
       case 8:
      cout<<" Enter the message"<<endl;
      gets(str);
   cout<<" Enter the key"<<endl;
   cin>>key;
      encode(str,key);
            break;
    case 9:
      decode(str,key);
            break;
    default:
     break;
}            
   }
}
void addOctalNumbers()
{
   int d1,d2,r,q,n1=0,n2=0,n=0,sum=0;
int o[100],i=0;
cout<<"Enter two decimal number: "<<endl;
cin>>d1;
cin>>d2;
q = d1;
while(q!=0)
{
      o[++i]= q % 8;
      q = q / 8;
      n++;
}

for(i=n;i>=1;i--)
{
n1=o[i]+n1*10;
}

q = d2;
i=0;
n=0;
while(q!=0)
{
      o[++i]= q % 8;
      q = q / 8;
      n++;
}
for(i=n;i>=1;i--)
{
n2=o[i]+n2*10;
}
sum=n1+n2;
cout<<" The decimal value"<<d1<<" equivalent octal number is "<<n1;
cout<<" The decimal value"<<d2<<" equivalent octal number is "<<n2;
cout<<" Sum of two octal number "<< n1 <<" "<<n2<<" is "<<sum;

}
void characterCount()
{
   string str;
   int i,count=0;
   cin>> str;
   for(i = 0; i < str.size(); ++i) {
        if (!isspace(str[i]))
           ++count;
   }
      cout<<"The number of non-blank characters are:"<<" "<<count<<endl;   
}
void convertBase(int num, int b)
{
        if (num == 0)
        return;
     int x = num % b;
     num /= b;
     if (x < 0)
        num += 1;
     convertBase(num, b);
  cout<< x < 0 ? x + (b * -1) : x;
     return;
}
void reverseString()
{
   char a[20],a1[20];
int i,j;
cout<<"Enter any String:"<<" ";
gets(a);
cout<<"Reverse of the string is: ";
for(i=0;a[i]!='';++i);
  for(j=i-1;j>=0;--j)
cout<<a[j];
}
void displayLargeandSmall()
{
     int a[50],size,i,big,small;
cout<<" Enter the size of the array: ";
cin>>size;
for(i=0;i<size;i++)
      cin>>a[i];

big=a[0];
for(i=1;i<size;i++)
{
      if(big<a[i])
           big=a[i];
}
cout<<" Largest element: "<<big;

small=a[0];
for(i=1;i<size;i++)
{
      if(small>a[i])
           small=a[i];
}
cout<<" Smallest element: "<<small;
}

void standardDeviation()
{
float sd,avg,sum=0;
    int n,a[20],i,j;
float sd,b[20],sum2=0;
    cout<<"enter the number of elements";
    cin>>n;
    cout<<"enter the elements";
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    avg=sum/n;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                int temp;
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
  
   
    for(i=0;i<n;i++)
    {
        b[i]=pow((a[i]-avg),2);
        sum2+=b[i];
    }
    sd=sqrt(sum2/n);
    cout<<" The Standard deviation is "<<sd;

}
void secondDegreeEquation()
{
   float a,b,c,d,root1,root2;
cout<<"Enter value of a, b and c : ";
cin>>a>>b>>c;

d=b*b-4*a*c;

if(d==0)
{
  root1=(-b)/(2*a);
  root2=root1;
  cout<<"Roots are real & equal";
}
else if(d>0)
{
  root1=-(b+sqrt(d))/(2*a);
  root2=-(b-sqrt(d))/(2*a);
  cout<<"Roots are real & distinct";
}
else
{
  root1=(-b)/(2*a);
  root2=sqrt(-d)/(2*a);
  cout<<"Roots are imaginary";
}

cout<<" Root 1= "<<root1<<" Root 2= "<<root2;

}
void encode(char e[],int key)
{
   int i;
    for(i=0;i<strlen(e);++i)
    {
        e[i] = e[i] - key;
    }
}
void decode(char e[],int key)
{
   int i;
    for(i=0;i<strlen(e);++i)
    {
        e[i] = e[i] + key;
    }
}