It\'s c++ ECE 270 Test I Oct. 22, 2017 Honor code in effect Closed Book and Note
ID: 3599148 • Letter: I
Question
It's c++
ECE 270 Test I Oct. 22, 2017 Honor code in effect Closed Book and Notes Group starting at 2:00 PM must finish by 2:50 PM (s point bonus if finished by Group starting at 2:55 PM must finish by 3:45 PM (5 point bonus itf 2:4O PM) finished by 3:35 PM) (S point bonus if the following is done correctly!) On the desktop, create a folder beginningw number in the upper-left corner of this sheet followed by your first initial and five letters of your last name. The two projects are to be saved to this folder. Please note that your programs may be lost if your work is not saved correctly 1. (40) Write a program that will prompt the user for some number of integers, read in that number of integers, find the sum of the digits and print out the the number of digits that are even. Save the source file as progl cpp Write a program that will use the following function prototypes: bsoluteData(double data[D: //ask user for number of points, read in points and store the absolute 2. (60) value of each entered value in data and return number of points void sort double datal], int numpts )://sort the values from lowest to highest ouble bigSum(double datal, int numpts); //return the sum of all values greater than 10 In main, call readAbsolute Data to read in the number of points along with the absolute value of the data points. In sort, the data read in by readAbsoluteData is to be sorted. In bigSum, find the sum of all values greater than 10. Each function including main is worth 15 points. Don't try to enter all the code and then debug. Instead work on main and readAbsoluteData and get that to work before going on to the other functions. Save the ource file as prog2.cpp. sure to add your name as a comment at the beginning of each program!! ure to have your name printed out in each program and sign the honor code below.Explanation / Answer
1.
#include <iostream>
using namespace std;
int main() {
int n,p,digit,sum_of_digit=0,number_of_even_digits=0;
cout<<"Enter some number of integers = ";
cin>>n;
while(n>0)
{
digit = n%10;
sum_of_digit+=digit;
if(digit%2==0)
number_of_even_digits++;
n=n/10;
}
cout<<" Sum of the digits"<<sum_of_digit;
cout<<" number of even digits"<<number_of_even_digits;
}
2.
#include <iostream>
using namespace std;
int readAbsoluteData(double (&data)[1000])
{
int i,n;
double n1;
cout<<"enter the number of points:";
cin>>n;
for(i=0;i<n;++i)
{
cout<<" enter the point:";
cin>>n1;
if(n1<0)
n1*=-1;
data[i]=n1;
}
return n;
}
void sort(double (&data)[1000], int numpts)
{
int c,d;
double swap;
for (c = 0 ; c < ( numpts - 1 ); ++c)
{
for (d = 0 ; d < numpts - c - 1; ++d)
{
if (data[d] > data[d+1])
{
swap = data[d];
data[d] = data[d+1];
data[d+1] = swap;
}
}
}
}
double bigSum(double data[1000], int numpts)
{
int i;
double sum=0;
for(i=0;i<numpts;++i)
{
if(data[i]>10)
sum+=data[i];
}
return sum;
}
int main() {
double data[1000];
int numpts = readAbsoluteData(data);
sort(data,numpts);
double sum = bigSum(data,numpts);
cout<<" sum of points greater than 10: "<<sum; return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.