In: Computer Science
Complete the following exercises using C programming language. Take screenshots of the code and its output where specified and paste them into in a well-labeled Word document for submission.
Scenario
Assume you are the CIO of an organization with three different IT department locations with separate costs. You want a program to perform simple IT expenditure calculations. Your IT expenditure target is $35,000 per site.
Site expenditures:
Site 1 – $35,000.
Site 2 – $37,500.
Site 3 – $42,500.
Exercise 4 – Evaluating a Program’s Security
Examine the programs that you wrote and identify code that might have security-related implications. Explain a how that portion of code either enhances code security or introduces a security vulnerability.
Submit your well-labeled Word document that includes all elements specified in the exercises.
This is the brute-force method of security implementation:
Here is the code>>>
#include <stdio.h>
void checkExpenditure(int value){
int target=35000;
if(value>target) printf("The expenditure is exceed.\n");
else printf("The expenditure is not exceed.\n");
}
int main()
{
int site1=35000;
int site2=37500;
int site3=42500;
checkExpenditure(site1);
checkExpenditure(site2);
checkExpenditure(site3);
return 0;
}
Here is the live output of the program>>>
Security Implications>>>
Here is a more secure implementation>>>
#include <stdio.h>
void checkExpenditure(int value){
if(value>0){
int target=35000;
if(value>target) printf("The expenditure is exceed.\n");
else printf("The expenditure is not exceed.\n");
}else printf("Invalid expenditure entered.\n");
}
int main()
{
int site1=35000;
int site2=37500;
int site3=42500;
int site4=-1;
int site5=0;
checkExpenditure(site1);
checkExpenditure(site2);
checkExpenditure(site3);
checkExpenditure(site4);
checkExpenditure(site5);
return 0;
}
Here are the live output and code snippet>>>
Security Implications:
Here is the updated code>>>
#include <stdio.h>
void checkExpenditure(float value){
if(value>0){
float target=35000.00f;
if(value>target) printf("The expenditure is exceed.\n");
else printf("The expenditure is not exceed.\n");
}else printf("Invalid expenditure entered.\n");
}
int main()
{
float site1=35000.4f;
int site2=37500;
float site3=42500.5f;
int site4=-1;
int site5=0;
checkExpenditure(site1);
checkExpenditure(site2);
checkExpenditure(site3);
checkExpenditure(site4);
checkExpenditure(site5);
return 0;
}
Here is the code output>>
Security Implications: