Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this part of my assignment. All code is provided for context! You have been given 8 C files, each has the

I need help with this part of my assignment. All code is provided for context!
You have been given 8 C files, each has the same logic, expressed in different ways. Each of the files is incomplete, marked by TBD. You must replace each TBD entry with appropriate C code. You must NOT alter any of the existing lines. You are only allowed to replace each TBD line with new lines.
Each of the C programs do exactly the same task. Given a list of numbers on the command line, they find the sum, sum of squares and the sum of cubes. You do not have to add error checking. You can safely assume that all numbers are given nicely as integers on the command line and are in the range of -100 to 100.
The output from all programs will be the same for the same arguments. For example, the sum of the list (3482-4-2213-8303) is 23, the sum of squares is 15447 and the sum of cubes is 10397.
The 'doit.sh' script is available to use if you choose. It runs on Linux and will compile and run each of the C programs for you. The script is optional and does not need to be submitted.
Part I: Implementation.
Get each of the 8 C files to compile and produce the results such as given above. Submit your code (and output) in Blackboard. Please submit a single zip file, called Lastname_abc123.zip, with the following contents:
Your 8 modified C files
Optional: your modified python file
Output from your C files (and optional python file) in a single file called sum.out.
Answers to the following Part II questions in a text file called sum.txt.
Here is an implementation of sum2() in sum1.c
-
static int sum2(int argc, char *argv[]){
int sumsq =0;
int i;
for (i =1; i < argc; i++){
int n = atoi(argv[i]);
sumsq += n * n;
}
return sumsq;
}
-
Code given with assignment:
// gcc -Wall sum1.c -o sum1
//./sum148-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
static int sum1(int argc, char *argv[]){
TBD
}
static int sum2(int argc, char *argv[]){
TBD
}
static int sum3(int argc, char *argv[]){
TBD
}
int main(int argc, char *argv[]){
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", x, y, z);
return 0;
}
-
// gcc -Wall sum2.c -o sum2
//./sum248-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
static int x; // Sum
static int y; // Sum squares
static int z; // Sum cubes
static void sum2(int argc, char *argv[]){
TBD
}
int main(int argc, char *argv[]){
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", x, y, z);
return 0;
}
-
// gcc -Wall sum3.c -o sum3
//./sum348-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
typedef struct {
int x; // Sum
int y; // Sum squares
int z; // Sum cubes
} sum_t;
static sum_t *sum3(int argc, char *argv[]){
static sum_t sum;
TBD
return
}
int main(int argc, char *argv[]){
sum_t *m;
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", m->x, m->y, m->z);
return 0;
}
-
// gcc -Wall sum4.c -o sum4
//./sum448-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
typedef struct {
int x; // Sum
int y; // Sum squares
int z; // Sum cubes
} sum_t;
static void sum4(int argc, char *argv[], sum_t *sum){
TBD
}
int main(int argc, char *argv[]){
sum_t m;
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", m.x, m.y, m.z);
return 0;
}
-
// gcc -Wall sum5.c -o sum5
//./sum548-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
typedef struct {
int x; // Sum
int y; // Sum squares
int z; // Sum cubes
} sum_t;
static sum_t *sum5(int argc, char *argv[]){
sum_t *sum =(sum_t *) malloc(sizeof(sum_t));
TBD
return sum;
}
int main(int argc, char *argv[]){
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", m->x, m->y, m->z);
return 0;
}
-
// gcc -Wall sum6.c -o sum6
//./sum648-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
static void sum6(int argc, char *argv[], int *x, int *y, int *z){
TBD
}
int main(int argc, char *argv[]){
int x, y, z;
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", x, y, z);
return 0;
}
-
// gcc -Wall sum7.c -o sum7
//./sum748-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
#define sum7(argc, argv, x, y, z)\
x =0; \
y =0; \
z =0; \
int i; \
TBD
}
int main(int argc, char *argv[]){
int x, y, z;
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", x, y, z);
return 0;
}
-
// gcc -Wall sum8.c -o sum8
//./sum548-5020
// prints: Sum=27 Sum2=505 Sum3=8451
#include
#include
// sums[0] is sum, [1] is sum squares, [2] is sum cubes
static void sum8(int argc, char *argv[], int *sums){
TBD
}
int main(int argc, char *argv[]){
int sums[3]; // sums[0] is sum, [1] is sum squares, [2] is sum cubes
TBD
printf("Sum=%d Sum2=%d Sum3=%d
", sums[0], sums[1], sums[2]);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

5. Describe the visual representations, or models, of communication

Answered: 1 week ago