Coursehelp
April 16, 2019

## (Solved) : Work Area Results Codelab Analysis Compiler Error S Activity Hints Aimost Certainily Using Q31677244 . . .

WORK AREA RESULTS CODELAB ANALYSIS: COMPILER ERROR(S) activity More Hints You aimost certainily should be using: setw Type Ca I haven’t yet seen a correct solution that uses: !havent yet seen a correct solution that uses: % Want More Hints? Click here COMPILER ERROR MESSAGES ctest-opp1612 errors a function-definition is not alloved here betor token CTest.opp:232serrorsa funetion-definition is not alloved bere befor oken inc1ade clostrea d String 3 #inelude Show transcribed image text

. . .

OR
OR

## Questions viewed by other students

• QUESTION : (Solved) : Code Statsc Include Include Include Statsh Todo Fix Error Function Void Readinarray Int Ar Q35261596 . . .

This is the code:

stats.c:

#include<stdlib.h>

#include<stdio.h>

#include “stats.h”

//TODO: fix the error in this function

void readInArray(int *arr, int size) {

int i;

printf(“Enter your list of numbers: “);

for (i = 0; i < size; i++) {

//

scanf(“%d”, &arr[i]);

}

return;

}

int * generateRandomArray(int size) {

int * randomArr = malloc(sizeof(int) * size);

for(int i=0; i<size; i++) {

randomArr[i] = rand();

}

return randomArr;

}

void printArray(const int *arr, int size) {

printf(“[“);

for(int i=0; i<size-1; i++) {

printf(“%d, “, arr[i]);

}

printf(“%d ]n “, arr[size-1]);

}

//change the getMean function to get parameters as array andsize,CHEGGEA

double getMean( const int *arr,int size )

//double getMean( , ) {

{

double sum=0;

int i;

for(i = 0; i < size; i++)

{

sum+=arr[i];

}

return sum/size;

}

//change the getMean function to get parameters as array andsize,CHEGGEA

int getMin( const int *arr,int size )

//int getMin( , ) {

{

int i;

int min=arr[0];

for(i = 0; i < size; i++)

{

if(min > arr[i])

min=arr[i];

}

return min;

}

//change the getMean function to get parameters as array andsize,CHEGGEA

int getMax(const int *arr ,int size )

//int getMax( , )

{

int i;

int max=arr[0];

for(i = 0; i < size; i++)

{

if(max < arr[i])

max=arr[i];

}

return max;

}

===================

stats.h

/**

* This function prompts and reads in a collection of numbers

* from the standard input and populates the given array. The

* provided array must be properly initialized for thisfunction

* to work.

*/

/**

* Generates a random array of integers of the given

* size. This function assumes that the random number

* generator has already been seeded.

*/

int * generateRandomArray(int size);

/**

* Prints the given array to the standard output

*/

void printArray(const int *arr, int size);

/*

* TODO:

* 1. Write prototypes for each of these functions

* 2. Write documentation for each of these functions

* 3. Implement the functions in stats.c

*/

//added parameters to the following functions

double getMean( const int *arr,int size );

int getMin( const int *arr,int size );

int getMax(const int *arr ,int size );

================

This what was given for statsMain.c:

/**
* Statistics main driver program
*/
#include <stdlib.h>
#include <stdio.h>

#include “stats.h”

#define SIZE 500

int main(int argc, char** argv) {

//seed the random number generator with the current time
srand(time(NULL));

int min, max, size;
double mean;

printf(“Enter the amount of numbers you’d like to find the statsfor: “);
scanf(“%d”, &size);

if(size > MAX_SIZE) {
printf(“ERROR: program does not support that manyintegers!”);
exit(1);
}

//TODO: declare a static array “large enough” tohold as many integers as we’ll need

//TODO (Activity 3): change your delcaration andinitialization to use
// a dynamic array and malloc instead

//TODO: pass the appropriate variable

//TODO: pass the appropriate variables to yourfunctions here
min = getMin( , );
max = getMax( , );
mean = getMean( , );
printArray( , );

printf(“Min: %dn”, min);
printf(“Max: %dn”, max);
printf(“Mean: %.2fn”, mean);

return 0;
}

What should I do for statsMain.c

3.1 Static Arrays Navigate back to the statistics directory. Several files have been provided for you. The stats.c and stats.h file define several utility functions to manipulate arrays and to compute statistics on those arrays. The statsMain.c file contains a main driver program. Recall that you will compile these files using: gcc -c stats. gcc -o runstats stats. o statsMaln·c In this activity, you will implement and use several functions that use arrays as parame- ters. When passed as a parameter to a function, the function also needs to be told how large the array is; typically an integer size variable is passed with any array parameter You will also declare and populate a static array to test your functions. Instructions 1. A function, readInArray has been provided for you that takes an array and its size and prompts the user to enter values to populate the array. However, there is an error in the function: examine the scanf call and determine what is wrong and fix it before proceeding 2. Using the other functions as a reference, implement the getMin, getMax, and getMean functions. You will need to provide the correct function signature in both the header file and source file 3. In the statsMain.c declare a static array that is “large enough” as indicated by the other clues in the code. Use your declared static array as an argument to readInArray and the other function calls. 4. Run your program and demonstrate it to a lab instructor Show transcribed image text

. . .

• QUESTION : (Solved) : Code Specify Data Exposed Line S Source Present Vulnerability Describe Would Fix Vulnerabl Q34414183 . . .

For each code specify:

What data is being exposed and how?

What line(s) in the source present the vulnerability?

Describe how you would fix the vulnerable code.

CWE615_Info_Exposure.c

#include “std_testcase.h”

#include

{
int j;
for(j = 0; j < 1; j++)
{
{
HANDLE hUser;
char * domain = “Domain”;
/* Use the password in LogonUser() to establish that it is”sensitive” */
if (LogonUserA(
domain,
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&hUser) != 0)
{
/* Logged in XXXXX Smith using password ABCD1234 */
printLine(“User logged in successfully” );
CloseHandle(hUser);
}
else
{
}
}
}
}

int main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine(“Calling good()…”);
CWE615_Info_Exposure_good();
printLine(“Finished good()”);
#endif /* OMITGOOD */
return 0;
}

CWE535_Info_Exposure_Shell.c

#include “std_testcase.h”

#include

#include

{
int j;
for(j = 0; j < 1; j++)
{
{
HANDLE pHandle;
wchar_t * domain = L”Domain”;
if (fgetws(password, 100, stdin) == NULL)
{
printLine(“fgetws() failed”);
/* Restore NUL terminator if fgetws fails */
}
/* Remove the carriage return from the string that is inserted byfgetws() */
{
}
/* Use the password in LogonUser() to establish that it is”sensitive” */
if (LogonUserW(
domain,
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&pHandle) != 0)
{
printLine(“User logged in successfully.”);
CloseHandle(pHandle);
}
else
{
}
}
}
}

int main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine(“Calling good()…”);
CWE535_Info_Exposure_Shell_good();
printLine(“Finished good()”);
#endif /* OMITGOOD */
return 0;
}

#endif

CWE534_Info_Exposure_Debug.c

#include “std_testcase.h”

#include

#include

{
int j;
for(j = 0; j < 1; j++)
{
{
HANDLE pHandle;
wchar_t * domain = L”Domain”;
FILE * pFile = fopen(“debug.txt”, “a+”);
if (fgetws(password, 100, stdin) == NULL)
{
printLine(“fgetws() failed”);
/* Restore NUL terminator if fgetws fails */
}
/* Remove the carriage return from the string that is inserted byfgetws() */
{
}
/* Use the password in LogonUser() to establish that it is”sensitive” */
if (LogonUserW(
domain,
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&pHandle) != 0)
{
printLine(“User logged in successfully.”);
CloseHandle(pHandle);
}
else
{
}
if (pFile)
{
fclose(pFile);
}
}
}
}

int main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine(“Calling good()…”);
CWE534_Info_Exposure_Debug_good();
printLine(“Finished good()”);
#endif /* OMITGOOD */
return 0;
}

#endif

CWE226_Sensitive_Information.c

#include “std_testcase.h”

#include
#include

{
int j;
for(j = 0; j < 1; j++)
{
{
HANDLE hUser;
wchar_t * domain = L”Domain”;
if (fgetws(password, 100, stdin) == NULL)
{
printLine(“fgetws() failed”);
/* Restore NUL terminator if fgetws fails */
}
/* Remove the carriage return from the string that is inserted byfgetws() */
{
}
/* Use the password in LogonUser() to establish that it is”sensitive” */
if (LogonUserW(
domain,
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&hUser) != 0)
{
printLine(“User logged in successfully.”);
CloseHandle(hUser);
}
else
{
}
}
}
}

#ifdef INCLUDEMAIN

int main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine(“Calling good()…”);
CWE226_Sensitive_Information_good();
printLine(“Finished good()”);
#endif /* OMITGOOD */
return 0;
}

#endif

. . .

• QUESTION : (Solved) : Code Snippet Part Restaurant Menu Program Previously Used Lab Add Choice Drink Add Necessa Q34744185 . . .

The code snippet below is part of the restaurant menu programyou previously used in the lab. Add a choice for a drink. Add thenecessary code to allow the program to calculate the total price oforder for the user. Assume the following price list: Hamburger \$5Hotdog \$4 Fries \$3 Drink \$2 The program should allow the user tokeep entering order until choosing to exit. At the end the programprints an order summary like this: You ordered 2 hamburger(s), 1hotdog(s), 3 fries, 0 drink(s). Price: \$23 HST:  \$2.99Total: \$25.99

do { printf(“What do you want to eat today?n”); printf(“1.Hamburgern”); printf(“2. Hotdogn”); printf(“3. Friesn”);printf(“4. Exitn”); printf(“Enter your choice: “); scanf(“%d”,&choice); switch(choice){ case 1: printf(“You ordered ahamburgern”); break; case 2: printf(“You ordered a hotdogn”);break; case 3: printf(“You ordered friesn”); break; case 4:printf(“Order finished, thank you!n”); break; default:printf(“Wrong choice! try again: “); } } while (choice != 4);

. . .

• QUESTION : (Solved) : Code Snippet Array Arr Declared Line 7 Size 4 4 Initial Values Also Defined However Line 9 Q26674021 . . .

In the code snippet below, the array

arr

is declared in line #7 with a size of 4

with 4 initial values also defined.

However, in line #9 to #11, the arrays are accessed to beprinted. The loop is

set at SIZE+2 in line #9 which means that we will access valuesbeyond that of

the array. C++ does not check for out-of-bound access in anarray.

Output printed from the loop in #9 to #11 is shown below.

Last two values are invalid because they are values beyond thearray.

You will now define an array that will check for the arraybounds.

Design an array called

myArray

according to this declaration.

Here is definition of empty constructor in line #13

Here is definition of constructor in line #11 specifying theupper bound of the

array

4 const int SIZE=4; 6 int main() int arr[SIZE] {3,14, 7,81); = 8 9, 10 for(int 1-0;1 Show transcribed image text