Please I need a C++ program to the compute McCabe’s V(G) value of my program (or
ID: 3771169 • Letter: P
Question
Please I need a C++ program to the compute McCabe’s V(G) value of my program (or algorithm).
That means you should make a program to count the McCabe's of my code that I posted here. and I have the psecode .and I need the implementation by C++ so, you should put my code in the text file and let the code that you will make by C++ calculate The McCabe's of my code.
Pseudo code:
1-Copy the code to text file.
2-Read the file line by line and word by word.
3-When encounter one of the keywords in the table like (For,if,while,Else if,else end), add it to the stack.
4-When encounter “end” go backwards in the stack until found one of the keywords.
5-Count the number of indexes when scanning the stack.
6-Set the top index for the stack to the last keyword found.
7-Repeat from c. until the stack is empty.
here my code that I need you to calculate the McCabe’s V(G) value by the code that you will make it
#include <iostream>
using namespace std;
double TaxRate (int INCOME, int N_Children)
{
if (INCOME<15000)
{
switch(N_Children)
{
case 0:
return INCOME*0.05;
break;
case 1:
return INCOME*0.03;
break;
case 2:
return INCOME*0.02;
break;
default:
//Do something
break;
}
}
else if (INCOME<25000)
{
switch(N_Children)
{
case 0:
return INCOME*0.10;
break;
case 1:
return INCOME*0.08;
break;
case 2:
return INCOME*0.06;
break;
default:
//Do something
break;
}
}
else if (INCOME<55000)
{
switch(N_Children)
{
case 0:
return INCOME*0.15;
break;
case 1:
return INCOME*0.12;
break;
case 2:
return INCOME*0.11;
break;
default:
//Do something
break;
}
}
else if (INCOME<105000)
{
switch(N_Children)
{
case 0:
return INCOME*0.25;
break;
case 1:
return INCOME*0.23;
break;
case 2:
return INCOME*0.20;
break;
default:
//Do something
break;
}
}
else if (INCOME<205000)
{
switch(N_Children)
{
case 0:
return INCOME*0.28;
break;
case 1:
return INCOME*0.25;
break;
case 2:
return INCOME*0.30;
break;
default:
//Do something
break;
}
}
else if (INCOME< 255000)
{
switch(N_Children)
{
case 0:
return INCOME*0.30;
break;
case 1:
return INCOME*0.28;
break;
case 2:
return INCOME*0.30;
break;
default:
//Do something
break;
}
}
else if (INCOME< 305000)
{
switch(N_Children)
{
case 0:
return INCOME*0.35;
break;
case 1:
return INCOME*0.30;
break;
case 2:
return INCOME*0.30;
break;
default:
//Do something
break;
}
}
else if (INCOME< 405000)
{
switch(N_Children)
{
case 0:
return INCOME*0.40;
break;
case 1:
return INCOME*0.35;
break;
case 2:
return INCOME*0.30;
break;
default:
//Do something
break;
}
}
else
{
return INCOME*0.50;
}
return 0;
} // end calculate of TAX
double calculate (char type_of_people, int N_Children, int Tax, int INCOME)
{
switch(type_of_people)
{
case 'n':
return Tax = TaxRate(INCOME,N_Children);
break;
case 'b':
if(INCOME>65000)
{
return Tax = Tax + TaxRate(INCOME,N_Children);
}
else
{
INCOME = INCOME*0.065;
return INCOME;
}
break;
case 'm':
return Tax = Tax + (TaxRate(INCOME,N_Children)-(TaxRate(INCOME,N_Children)*0.75));
break;
case 's':
return Tax = Tax + (TaxRate(INCOME,N_Children)-(TaxRate(INCOME,N_Children)*0.70));
default:
break;
//Do something
}}
int main()
{
char type_of_people;
double INCOME, N_Children;
double Tax,y;
cout<<"please write appropriate letter for your situation:-"<<endl;
cout<<endl;
cout<<" letter | your situation "<<endl;
cout<<" b | Blind " <<endl;
cout<<" m | Military "<<endl;
cout<<" s | Student " <<endl;
cout<<" n | non of all " <<endl;
cout<<endl;
cout<<"your letter is ";
cin>>type_of_people;
if (type_of_people!='b'&& type_of_people!='m'&& type_of_people!='n'&& type_of_people!='s')
cout<<"wrong value"<<endl;
else
{
cout<<" your salary is: ";
cin>> INCOME;
if(INCOME<0)
cout<<"wrong value must be positive"<<endl;
else
{
y=INCOME; //for store the value before Social Security
cout<<"How many Children do you have? ";
cin>> N_Children;
INCOME = INCOME*0.065; // Social Security
if(type_of_people=='m')
INCOME =INCOME-INCOME*0.75; // Social Security for military
else
INCOME = INCOME;
Tax=INCOME;
cout<<"The Social Security tax is : $"<<Tax<<endl;
Tax = calculate(type_of_people, N_Children, Tax, y);
cout<<"Tax_Rate which you need to pay is: $"<<Tax<<endl;
}
}}
Explanation / Answer
else , end . they are separate words