Question

In: Computer Science

Complete the following exercises using C programming language. Take screenshots of the code and its output...

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.

Solutions

Expert Solution

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>>>

  • This ensures that if the expenditure is exceeded then the administrator gets notified as a message with proper information.
  • As this solves the basic problem of informing the administrators. But there are some problems still in the problem.
    • Firstly if the expenditure can't be zero or minus, but there is no check about this in the program. Let us solve the problem.

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:

  • In the above implementation, another problem is solved which was to tackle the zero or invalid condition.
  • But there is another issue at hand. If the user enters any float number which is not a full number the program can't handle the situation. Let's handle the situation.

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:

  • After these three updates, the code has solved three problems.
    • Firstly the code is more rigid by handling the zero or minus condition.
    • Secondly, the code sends feedback to the administrator.
    • Thirdly the program handles the float values as well.

Related Solutions

C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Exercises Code of Conduct Exercises Instructions:  Answer the following in complete sentences using the AICPA's revised Code...
Exercises Code of Conduct Exercises Instructions:  Answer the following in complete sentences using the AICPA's revised Code of Conduct, providing the ET references for each of your responses. For questions with multiple parts, include multiple ET references as appropriate. What are the three broad categories of safeguards identified in Part 1 of the Code, in the Conceptual Framework for members in public practice? Which category of safeguard cannot be relied upon, by itself, to reduce threats to an acceptable level?
Complete the following assignment in C programming language. Get the user’s first name and store it...
Complete the following assignment in C programming language. Get the user’s first name and store it to a char array Declare a character array to hold at least 20 characters. Ask for the user’s first name and store the name into your char array. Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces. Get 3 exam scores from the user: Declare an array of 3 integers Assume the scores are out...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
Code in C++ programming language description about read and write data to memory example.
Code in C++ programming language description about read and write data to memory example.
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace...
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace std; char ch; int main() {    cin >> ch;    cout << "You inputted " << ch << endl;    ch++;    cout << "Next character is " << ch << endl; if (ch <= ‘Z’)         cout << “Could be luppercase\n”;    return 0; }
How would I code the following in assembly language? Use the Keil programming environment to code...
How would I code the following in assembly language? Use the Keil programming environment to code the C8051F330 SiLabs 8051 micro controller. All the documentation is available on efundi. The program shall be done in assembler and you shall use the DJNZ instruction to generate a delay time to flash the LED. The LED shall flash in the following sequence: 1. On for 50mS, 2. Off for 400mS, 3. On for 50mS, 4. Off for 1.5S, 5. Repeat the sequence...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT