Question

PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES

PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES

PLEASE COMPLETE ALL ASPECTS OF PAPER

THANK YOU!!!

Objectives To learn to code, compile and run a program containing ARRAYS. . Assignment Plan and code a modular program utiliz

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <iostream>
#include <fstream>

using namespace std;

//function to find the max of a passed array and its size
int findMax(int a[],int size){
int max = a[0];
for(int i=0;i<size;i++){
if(a[i] > max){
max = a[i];
}
}
return max;
}
//function to find the minimum of an array which is passed and it its size
int findMin(int a[],int size){
int min = a[0];
for(int i=0;i<size;i++){
if(a[i] < min){
min = a[i];
}
}
return min;
}
//function to find the average of all numbers of the passed array, and its size
double findAverage(int a[],int size){
double sum = 0.0;
for(int i=0;i<size;i++){
sum += a[i];
}
double avg = sum/double(size);
return avg;
}
//function to find the number of n
int higher(int a[],int size,double avg){
//the array, its size and its average is passed
int n=0;
for(int i=0;i<size;i++){
if(a[i]>avg)
n++;
}
return n;
}
//main method
int main() {
int *odd = new int[50];
int *even = new int[50];
//opening the input file
fstream file;
file.open("input.txt");
int num,oddNum =0,evenNum = 0;
while(file>>num){
//here we are assuming negative integers can be classified as odd or even as well
if(num%2 != 0){
odd[oddNum] = num;
oddNum++;
}else if(num % 2 == 0){
even[evenNum] = num;
evenNum++;
}
}
//printing the odd array
cout<<"Odd Array: "<<endl;
for(int i=0;i<oddNum;i++){
cout<<odd[i]<<" ";
}
cout<<endl;
//printing the even Array
cout<<"\nEven Array: "<<endl;
for(int i=0;i<evenNum;i++){
cout<<even[i]<<" ";
}
cout<<endl;
//calling each function and displaying the labeled output
cout<<"\nThe average of each number in the even array is: "<<findAverage(even,evenNum)<<endl;
cout<<"The max number in the even array is: "<<findMax(even,evenNum)<<endl;
cout<<"The min number in the even array is: "<<findMin(even,evenNum)<<endl;
cout<<"Number of numbers higher than the average in the even array: "<<higher(even,evenNum,findAverage(even,evenNum))<<endl;

cout<<"\nThe average of each number in the odd array is: "<<findAverage(odd,oddNum)<<endl;
cout<<"The max number in the odd array is: "<<findMax(odd,oddNum)<<endl;
cout<<"The min number in the odd array is: "<<findMin(odd,oddNum)<<endl;
cout<<"Number of numbers higher than the average in the odd array: "<<higher(odd,oddNum,findAverage(odd,oddNum))<<endl;

return 0;
}
___________________________________

CODE IMAGES:

- *jhvhm.cpp - Code:Blocks 17.12 Eile Edit View Search Project Build Debug Fortran wxSmith Tools Tools+ Plugins DoxyBlocks Se- *jhvhm.cpp - Code::Blocks 17.12 Eile Edit View Search Project Build Debug Fortran wxSmith Tools Tools+ Plugins DoxyBlocks S

__________________________________________________

OUTPUT:

- х C:\Users\Win10\Documents\jhyhm.exe Odd Array: 17 95 21 63 47 19 41 85 -9 71 79 19 51 95 79 95 61 89 63 39 5 Even Array: 4

input.txt:

input.txt - Notepad Х File Edit Format View Help 146 30 82 90 56 17 95 16 48 26 4 58 0 78 92 60 12 21 63 47 19 41 90 85 14 -9

___________________________________________________

Feel free to ask any questions in the comments section
Thank You!

Add a comment
Know the answer?
Add Answer to:
PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

  • Write an object-oriented C++ program (i.e. a class and a main function to use it), using...

    Write an object-oriented C++ program (i.e. a class and a main function to use it), using pointer variables, that program that performs specific searching and sorting exercises of an array of integers. This program has six required outputs. Start by initializing an array with the following integers, in this order: 23, 17, 5, 90, 12, 44, 38, 84, 77, 3, 66, 55, 1, 19, 37, 88, 8, 97, 25, 50, 75, 61, and 49. Your array input may be hardcoded...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Student average array program

    Having a bit of trouble in my c++ class, was wondering if anyone can help.Write a program to calculate students' average test scores and their grades. You may assume the following input data:Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 68 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

  • Please solve this question using c++ language Problem 2. More Probleml. The program builds the array...

    Please solve this question using c++ language Problem 2. More Probleml. The program builds the array of integers that contains duplicates as well. Your program should find the sum of all unique elements in the array using a function findUniqueSum Arrays Write a program that as before asks the user to enter input as in оn Sample Input/Output Enter a list of numbers ending with -999 3 1 4 55-999 The sum of unique numbers is: 13 Enter a list...

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • Please Use C++ for coding . . Note: The order that these functions are listed, do...

    Please Use C++ for coding . . Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all.cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printodd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT