Sale!

ECE 361 Homework #1

$30.00

Category:
Rate this product

ECE 361
Homework #1

THE ASSIGNMENT WILL BE GRADED AND IS WORTH 100 POINTS. IT IS EASIEST TO GRADE, AND I BELIEVE EASIEST FOR YOU SUBMIT ANY SOURCE CODE FILES AS TEXT FILES INSTEAD OF TRYING TO CUT/PASTE YOUR CODE INTO A .doc OR .docx FILE.  SHORT ANSWER, TRUE/FALSE AND MULTIPLE CHOICE QUESTIONS SHOULD BE SUBMITTED IN A SINGLE TEXT OR .PDF FILE. CLEARLY NAME THE FILES SO THAT WE KNOW WHICH PROBLEM THE CODE REFERS TO AND SUBMIT THE PACKAGE AS A SINGLE .ZIP OR .RAR FILE (EX:  rkravitz_ece361f20_hw1.zip) TO YOUR D2L HOMEWORK #1 DROPBOX
Question 1 (35 pts) C Programming
The following questions ask you to debug or write a function.  Submit your source code but you do not have to compile and execute the program.
a.    [5] The following function is supposed to return true if any element of the array a[] has the value 0 and false if all elements are nonzero.  Sadly, it contains an error.  Find the error and show how to fix it.
boolean has_zero(int a[], int n)
{
int i;

for (i = 0; i < n, i++) {
return (a[i] != 0 ) ? false : true;
}
}

b.    [5] Indicate which of the following items SHOULD NOT be put into a C header (.h) file.  Why not?
a)    Function prototypes
b)    Source code for functions
c)    Macro definitions
d)    Type definitions
e)    Variables
c.    [5] We will cover recursion and recursive functions later in the term, but for now, let it suffice to say that Recursion is a computer programming technique involving the use of a procedure, subroutine, function, or algorithm that calls itself.  Recursive functions must have a termination condition else the functions may never return. Consider this C program:

The function sum() is called for the first time by the main program. From the second time on, it is called by itself.   How many times is sum() called altogether, including the call from main()?  Explain your answer and/or show your work.

d.    [20] Complete the code for the following three functions given a struct color as defined below:
typedef struct color {
int red;
int green;
int blue;
} color_t;

// returns a color_t struct containing the specified values
// for the red, green, and blue color members.
// if an argument is < 0 that color member is set to zero.
// if an argument is > 255 that color members is set to 255
color_t makeColor(int red, int green, int blue) {

}

// returns the value of the red member of the
int getRed(color_t c) {
// ADD YOUR CODE HERE

}

// returns true if all of the members of both color_t structs
// are the same
bool equalColor(color_t c1, color_t c2) {
// ADD YOUR CODE HERE

}

// returns a color_t struct that represents a darker version of the
// color in to color_t argument c except that each member
// has been multiplied by 0.7 with the result truncated to an integer
color_t makeDarkerColor(color_t c) {
// ADD YOUR CODE HERE
}
Question 2 (15 pts):  Short Answers
a.    [5] Provide a concise (a few sentences) answer for these questions:
1)    What does it mean to make a “commit” to a git repository?
•    what does it mean to make a commit to a git repository is that you save your changes to the local repository. When you use git add to mark the desired change, and then use commit to wrap up the change and save what you have just upload.

2)    What is the role of the “staging area” in a git repository?
•    What is a staging area in a git repository is it like a rough draft space where you add a file or multiple file that you going to save on the next commit command that you doing to use.

3)    How do you use the “staging area” to control what files you are committing to a repository?
•    You must track the file that you going to about to commit to the repository by telling git to track it with the status command. Once it is track git move them to staging area where they save the change in the file you just track to the repository.

b.    [5] GitHub provides a cloud-based host for your repositories.  Describe the process (you can include/discuss the relevant git commands if you’d like) to push your local repositories to “the cloud.”
•    The first thing you need to do is use “git init” to initialize a reposit for your file, then after that you use “get remote add orgin” to add the cloud location of the file. Second is you have to use “git add -A” to add all the file being track by git, and then use “git status” to have get notice all the change that you make to the files. Third you use “git commit-m” to save all the change and the file to the repository, and then “git push orgin master” this will push the local storage to the cloud storage for you.

c.    [5] What is a branch in git and how do you create one?  Give an example of how a branch can be used to debug a new code module without risking your working code.
What is a branch is basically you have a separate place to work where it won’t affect the main work place. This way whatever you test in the new work place will not affect the old one, and to create a branch in github you just need to use the command “git branch testing” which will create a separate file with the same code as the original for you to work. How branching can be used to debug new code module without risking your working code is you make a branch this in turn create a separate file for you to work on. Now you can modify the new file in anyway you want to test for bug, and all these change will not affect the original working code of your.

Question 3 (15 pts):  C Functions using Pointers
The following questions ask you to debug or write a function.  Submit your source code but you do not have to compile and execute the program.
a.    [5] Write the following function:
void split_date(int day_of_year, int year, int *month, int *day);

day_of_year is an integer between 1 and 366, specifying a particular day within the year
designated by the parameter year.  month and day point to variables in which the function
will store the equivalent month (1 – 12) and day within the month (1 – 31)

b.    [5] Write the following function:
int *find_largest(int a[], int n);
When passed an array a of length n, the function returns a pointer to array’s largest element.
c.    [5] Having to check the return value of malloc() (or any other memory allocation function) each time we call it can become annoying and monotonous.  Write a function called my_malloc(int n_bytes) that servers as a “wrapper” for malloc().  When we call my_malloc() and ask it to allocate n_bytes,  my_alloc() calls malloc(), tests to make sure that malloc() doesn’t return a null pointer and then returns the pointer from malloc().  Have my_malloc() print an error message and terminate the program if malloc() returns a null pointer.

Question 4 (35 pts):  Writing, compiling, and executing C programs
a.    [20] Write a C program that prompts the user to enter a U.S. dollar amount and then shows how to pay that amount using the smallest number of $20, $10, $5, and $1 bills.  Hint: Divide the amount by 20 to determine the number of $20 bills needed, and then reduce the amount by the total value of the $20 bills.  Repeat for the other bill sizes.  Be sure to use integer values throughout, not floating point numbers.

b.    [15] Compile, debug, and execute your program with the gcc tool chain.  Include enough test cases to show that your program works correctly.  Submit your source code and a console transcript showing that your program ran successfully.

ECE 361 Homework #1
$30.00
Open chat
Need help?
Hello
Can we help?