Part A and B please.
The speeding ticket fine policy in Potyomkin village is $60.00 plot$5.OO for each mph over the speed limit. Moreover, the fine is doubled for any speed limit violation in a construction zone. Furthermore, a penalty of $250.00 is added for any speed over 90 mph. Write a function, called speeding, that takes three formal parameters a speed limit (int), clocked speed (int) and whether the speed limit violation took place in a construction zone or not (\' \'y\' or \' \'n\') as input, and either returns zero indicating the speed was legal or returns the amount of the fine. If the speed Is illegal. The caller of the function speeding() in the test() function then prints a message using the format shown in the next problem. You must use if statements In your solution. Your speeding() function must not print anything. Do not import external module in your solution. Write a test function, called test(), to test the speeding() function with the following actual parameters and write a message accordingly: Call test() in your program and show the result. Examples of the correct output formal include: Speeding Weirton fine for speed 35 in 50 mph zone (contraction = \'Y\'): $0. 00 Speeding violation fine for speed 95 in 80 mph zone (contraction = \'n\'): $385.00
Please find belowe the required answer in C++
#include<bits/stdc++.h>
using namespace std;
int speeding(int sp_limit,int clo_speed,char ch) //speeding func with 3 parameters
{
if(clo_speed<=sp_limit) //check if speed is legal or not
return 0;
else
{
int excess=clo_speed-sp_limit;
int fine=60; // this case occurs when a speed violation is encountered , so fine is initialised to 60.
if(clo_speed>=90)
fine+=250;
fine=fine+(excess*5); //fine changed according to the mph violated.
if(ch==\'y\') //fine changed according to violation in construction zone
fine*=2;
return fine;
}
}
void test()
{
cout<<speeding(45,35,\'y\')<<endl;
cout<<speeding(45,55,\'y\')<<endl;
cout<<speeding(45,55,\'n\')<<endl;
cout<<speeding(45,95,\'y\')<<endl;
cout<<speeding(45,95,\'n\')<<endl;
}
int main()
{
test();
}