Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC 373 Computer Systems 1 Sections 401, 410 Fall 2018 Homework assignment 1 Due as specified on D2L Each problem below is worth 2 points,

CSC 373 Computer Systems 1 Sections 401, 410 Fall 2018

Homework assignment 1

Due as specified on D2L

Each problem below is worth 2 points, for a total of 10 points. Please see the file hw1_main.c for sample calls to each function. Note that I may test your code on other examples, so you should thoroughly test the functions that you write, beyond those provided in hw1_main.

Write 2 functions, called scan_2 and print_2. Here are prototypes for each:

void scan_2(int *i, char *c);

void print_2(int i, char c);

Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below.

int pow_xy(int *xptr, int y);

Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result.

Write a function called convert_temp. The prototype for this function is:

int convert_temp(int deg, char scale, int *dptr, char *sptr);

The function should convert a temperature from Fahrenheit to Celsius or vice versa, depending on the value of the parameter scale. The function should return an int reflecting whether or not the converted value *dptr is positive.

Write a function called init_array. It is passed 3 parameters, as specified in the prototype below:

int init_array(int array[ ], int len, int start_value);

The ith item in array should be initialized to the value start_value * i. Also, the function should return the sum of the values in array after initialization.

Write a function called reverse_numbers. The function is passed an array of ints (and of course its length as a 2nd parameter). The function should reverse the ordering of the numbers in the array. Here is its prototype:

void reverse_numbers(int nums[], int len);

#include  // includes your hw1.c file (not from C library) // note " " instead of < > #include "hw1.c" void test_p1() { printf(" p1 "); int integer; char character; printf("type an int and a char (no blanks) "); scan_2(&integer, &character); print_2(integer, character); } void test_p2() { printf(" p2 "); int x = 2; int *xptr = &x; printf("pow_xy %d 3 ", x); pow_xy(xptr, 3); printf("= %d ", x); } void test_p3() { printf(" p3 "); int new_degrees; char new_scale; convert_temp(32, 'F', &new_degrees, &new_scale); printf("32 F is %d %c ", new_degrees, new_scale); convert_temp(10, 'C', &new_degrees, &new_scale); printf("10 C is %d %c ", new_degrees, new_scale); } void test_p4() { printf(" p4 "); int numbers[5]; init_array(numbers, 5, 2); int i; for (i=0; i<5; i++) printf("%d ", numbers[i]); printf(" "); } void test_p5() { printf(" p5 "); int phone[] = {3, 1, 2, 3, 6, 2, 6, 1, 0, 6}; reverse_numbers(phone, 10); int i; for (i=0; i<10; i++) printf("%d ", phone[i]); printf(" "); } int main() { test_p1(); test_p2(); test_p3(); test_p4(); test_p5(); }
#include  //1 void scan_2(int *i, char *c) { } void print_2(int i, char c) { } //2 int pow_xy(int *xptr, int y) { return 0; } //3 int convert_temp(int degree, char scale, int *other_degree, char *other_scale) { return 0; } //4 int init_array(int array[ ], int len, int start_value) { return 0; } //5 void reverse_numbers(int nums[], int len) { }

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_2

Step: 3

blur-text-image_3

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago