Blog

Coursehelp
April 16, 2019
QUESTION : No Comments

(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 havent 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 <estrisp y Funoti Game 10 int naie O int k 13 14 and O 17 (Length jepecifier in your case 9 digita int nain O Opera ns k-27-9765432-432WORK 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

Expert Answer


. . .

OR
OR

Have a Comment on this Question?

Questions viewed by other students


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

    3.1 Static Arrays Navigate back to the statistics directory. Several files have been provided for you. The stats.c and stats.

    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.

    */

    void readInArray(int *arr, int size);

    /**

    * 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
       readInArray(, size);

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

    Expert Answer


    . . .


    view full answer
  • 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
    #pragma comment(lib, “advapi32.lib”)

    #define PASSWORD “ABCD1234!”
    #define USERNAME “XXXXX Smith!”

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

    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 */
    #ifndef OMITBAD
    printLine(“Calling bad()…”);
    CWE615_Info_Exposure_bad();
    printLine(“Finished bad()”);
    #endif /* OMITBAD */
    return 0;
    }

    CWE535_Info_Exposure_Shell.c

    #include “std_testcase.h”

    #include

    #include
    #pragma comment(lib, “advapi32.lib”)

    void CWE535_Info_Exposure_Shell_bad()
    {
    int j;
    for(j = 0; j < 1; j++)
    {
    {
    wchar_t password[100] = L””;
    size_t passwordLen = 0;
    HANDLE pHandle;
    wchar_t * username = L”User”;
    wchar_t * domain = L”Domain”;
    if (fgetws(password, 100, stdin) == NULL)
    {
    printLine(“fgetws() failed”);
    /* Restore NUL terminator if fgetws fails */
    password[0] = L’ ‘;
    }
    /* Remove the carriage return from the string that is inserted byfgetws() */
    passwordLen = wcslen(password);
    if (passwordLen > 0)
    {
    password[passwordLen-1] = L’ ‘;
    }
    /* Use the password in LogonUser() to establish that it is”sensitive” */
    if (LogonUserW(
    username,
    domain,
    password,
    LOGON32_LOGON_NETWORK,
    LOGON32_PROVIDER_DEFAULT,
    &pHandle) != 0)
    {
    printLine(“User logged in successfully.”);
    CloseHandle(pHandle);
    }
    else
    {
    printLine(“Unable to login.”);
    }
    fwprintf(stderr, L”User attempted access with password: %sn”,password);
    }
    }
    }

    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 */
    #ifndef OMITBAD
    printLine(“Calling bad()…”);
    CWE535_Info_Exposure_Shell_bad();
    printLine(“Finished bad()”);
    #endif /* OMITBAD */
    return 0;
    }

    #endif

    CWE534_Info_Exposure_Debug.c

    #include “std_testcase.h”

    #include

    #include
    #pragma comment(lib, “advapi32.lib”)

    #ifndef OMITBAD

    void CWE534_Info_Exposure_Debug_bad()
    {
    int j;
    for(j = 0; j < 1; j++)
    {
    {
    wchar_t password[100] = L””;
    size_t passwordLen = 0;
    HANDLE pHandle;
    wchar_t * username = L”User”;
    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 */
    password[0] = L’ ‘;
    }
    /* Remove the carriage return from the string that is inserted byfgetws() */
    passwordLen = wcslen(password);
    if (passwordLen > 0)
    {
    password[passwordLen-1] = L’ ‘;
    }
    /* Use the password in LogonUser() to establish that it is”sensitive” */
    if (LogonUserW(
    username,
    domain,
    password,
    LOGON32_LOGON_NETWORK,
    LOGON32_PROVIDER_DEFAULT,
    &pHandle) != 0)
    {
    printLine(“User logged in successfully.”);
    CloseHandle(pHandle);
    }
    else
    {
    printLine(“Unable to login.”);
    }
    fwprintf(pFile, L”User attempted access with password: %sn”,password);
    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 */
    #ifndef OMITBAD
    printLine(“Calling bad()…”);
    CWE534_Info_Exposure_Debug_bad();
    printLine(“Finished bad()”);
    #endif /* OMITBAD */
    return 0;
    }

    #endif

    CWE226_Sensitive_Information.c

    #include “std_testcase.h”

    #include
    #include
    #pragma comment(lib, “advapi32.lib”)

    #ifndef OMITBAD

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

    #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 */
    #ifndef OMITBAD
    printLine(“Calling bad()…”);
    CWE226_Sensitive_Information_bad();
    printLine(“Finished bad()”);
    #endif /* OMITBAD */
    return 0;
    }

    #endif

    Expert Answer


    . . .


    view full answer
  • 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);

    Expert Answer


    . . .


    view full answer
  • 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.

    4 const int SIZE=4; 6 int main() int arr[SIZE] {3,14, 7,81); = 8 9, 10 for(int 1-0;1 < SIZE+2;i++) { cout << arr[i] << ; 12 13 14 15 16 cout <<endl << endl; return e;

    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

    Expert Answer


    . . .


    view full answer