SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 13 Nov 2017 My Price 10.00

completed my program but it is not outputting correctly.

Hey I completed my program but it is not outputting correctly. May I get some help as to why this is? The pdf file is in the instructions, the zip file is the log files that are supposed to be outputted by my big40.c file and there are c files in here that are supposed to be compiled with my big40.c file.

  • #include "big40.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <ctype.h>


    Integer40 *big40Add(Integer40 *p, Integer40 *q) {
        if (p != NULL && q != NULL) {
            Integer40 *r = malloc(sizeof(Integer40));
            if (r != NULL) {
                r->digits = malloc(sizeof(int) * MAX40);
                if (r->digits != NULL) {
                    // s holds the sum of the digits.
                    // c holds the carry resulted by the sum
                    int i, s, c = 0;
                    for (i = 0; i < MAX40; i++) {
                        // Add the digits and carry of previous sum.
                        s = p->digits[i] + q->digits[i] + c;
                        // Check if carry exists.
                        if (s > 15) {
                            s -= 16;
                            c = 1;
                        } else {
                            c = 0;
                        }
                        r->digits[i] = s;
                    }
                    return r;
                }
            }
        }
        return NULL;
    }

    Integer40 *big40Destroyer(Integer40 *p) {
        if (p != NULL) {
            free(p->digits);
            free(p);
        }
        return NULL;
    }

    Integer40 *parseString(char *str) {
        if (str != NULL) {
            Integer40 *r = malloc(sizeof(Integer40));
            if (r !=  NULL) {
                r->digits = malloc(sizeof(int) * MAX40);
                if (r->digits != NULL) {
                    int len = strlen(str);
                    int i = MAX40 - 1;
                    int j = 0;
                    char c;
                    // If the string is of length less than MAX40 we pad
                    // the number with zeroes at the beginning.
                    if (len < MAX40) {
                        fprintf(stderr, "Input string has less than 40 digits, filling with zeroes.\n");
                        for (; i >= len; i--) {
                            r->digits[i] = 0;
                        }
                    }
                    for (; (j < len) && (i >= 0); j++) {
                        if (c >= '0' && c <= '9') {
                            // If character is a number, to get decimal
                            // equivalent subtract the ascii code by that of 0.
                            r->digits[i] = (int)c - 48;
                        } else if (c >= 'a' && c <= 'f') {
                            // If the character is an alphabet then subtract
                            // it by the ascii equivalent of 'a' and add 10 such
                            // that (int)'a' - (int)'a' + 10 gives 10 (decimal value of 0xa).
                            r->digits[i] = (int)c - 97 + 10;
                        }
                        i--;
                    }
                    return r;
                }
            }
        }
        return NULL;
    }

    Integer40 *fibBig40(int n, Integer40 *first, Integer40 *second) {
        if (first != NULL && second != NULL) {
            Integer40 *p, *q, *r, *z;
            int i = 0;
            // First create copy of the first and second numbers so
            // that we don't delete their memory while iterating.
            // Add with zero to both to get a new copy of same value.
            z = parseString("0");
            p = big40Add(first, z);
            q = big40Add(second, z);
            for (; i < n; i++) {
                r = big40Add(p, q);
                // We no longer need p so we destroy
                // it to free up some space.
                big40Destroyer(p);
                p = q;
                q = r;
            }
            return r;
        }
        return NULL;
    }

    void big40Rating(void) {
        big40RatingStruct rating;
        rating.NID = malloc(sizeof(char) * 11);
        strcpy(rating.NID, "ta202540");
        rating.degreeOfDifficulty = 3.5;
        rating.duration = 20;
        fprintf(stderr, "%s;%f,%f", rating.NID, rating.degreeOfDifficulty, rating.duration);
    }

    Integer40 *loadHWConfigVariable(int doSeed) {
        Integer40 *r = malloc(sizeof(Integer40));
        if (r != NULL) {
            r->digits = malloc(sizeof(int) * MAX40);
            if (r->digits != NULL) {
                int i = 0, j;
                if (doSeed == 1) {
                    // Seed the random number generator if required.
                    srand(time(NULL));
                }
                for (; i < 10; i++) {
                    if (doSeed == 0) {
                        // Reset the seed for the rand() at every iteration,
                        // to generate a repeating pattern.
                        srand(1);
                    }
                    for (j = 0; j < 4; j++) {
                        r->digits[i * 4 + j] = rand() % 16;
                    }
                }
                return r;
            }
        }
        return NULL;
    }

    Integer40 *loadCryptoVariable(char *inputString) {
        if (inputString != NULL) {
            char *str = malloc(sizeof(char) * (MAX40 + 1));
            if (str != NULL) {
                FILE *fp;
                fp = fopen(inputString, "r");
                if (fp != NULL) {
                    while (!feof(fp)) {
                        // Read the first line of the file and try to parse it.
                        // Return at the first line itself.
                        if (fgets(str, MAX40 + 1, fp)) {
                            fclose(fp);
                            return parseString(str);
                        }
                    }
                    fclose(fp);
                }
            }
        }
        return NULL;
    }

Attachments:

Answers

(5)
Status NEW Posted 13 Nov 2017 12:11 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)