EC330 Applied Algorithms and Data Structures for Engineers Homework 1 solution

$24.99

Original Work ?

Download Details:

  • Name: Homework-1-n4b4vo.zip
  • Type: zip
  • Size: 854.01 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (4 votes)

5.Programming [40 pt]
Make sure to write your name and BU ID in a comment at the top of the program,
along with your collaborator’s name and BU ID, if any.
a) You are given an array of integers. Suppose every integer appears twice in this
array except for one. Write a C++ program that finds the integer that occurs only
once. [20 pt]
You are given a header file and a sample test program. Your job is to implement the
function findSingle. Your program must compile and run on the lab computers
using the command-line interface as follows.
> g++ -std=c++11 (-o myProgram) testProblem5a.cpp Problem5a.cpp
Submit your solution in a single file Problem5a.cpp. The most efficient solution(s)
will receive an extra credit of 0.1 point for the final class grade (out of 100).
b) Write a C++ program that keeps summing the digits of a positive integer until the
sum becomes a single digit. [20 pt]
Example:
Input: 12345
Output: 6
Explanation: 1+2+3+4+5 = 15 à 1+5 = 6
Another example:
Input: 982018
Output: 1
Explanation: 9+8+2+0+1+8 = 28 à 2+8 = 10 à 1+0 = 1
Again, you are given a header file and a sample test program. Your job is to
implement the function sumDigit. Similar to a), your program must compile and run
on the lab computers using the command-line interface as follows.
> g++ -std=c++11 (-o myProgram) testProblem5b.cpp Problem5b.cpp
Submit your solution in a single file Problem5b.cpp. The most efficient solution(s)
will receive an extra credit of 0.1 point for the final class grade (out of 100).