NOTE – You may use C++ - but you MAY NOT use #include
<string> The goal is to use C-Style character array based
strings.
You will put all of your code in this file.
You may use any technique we have learned so far.
Specifications:
This assignment is split into several parts. The goal is to get you used to working with C/C++ run-time arrays and strings.
Part 0 – Create a Menu
You should create a menu that gives access to each of the parts of the assignment.
Show this menu and make it function properly. If the user inputs something incorrect, correct them and loop the menu and prompt.
Welcome to Assignment 3!
Menu:
1 – 1D Math
2 – Single Dimension Character Processing
3 – Two-D Character Processing
4 - Exit
Choose an option:
Part 1 – 1D Math
Write a function to drive part 1. Write several other functions to complete each task.
A – Fill the Array)
Ask the user for a size and dynamically allocate an integer array based on that size.
Ask the user for a minimum integer and a maximum integer. Fill the array with random integers between the minimum value and maximum value entered.
Sort it! (see extra credit opportunity below) Display the
contents of the array.
Calculate and output:
The average of the array
The median of the array
The number of unique (non-repeated) numbers in the array The
number of numbers that were duplicated
o Note: how many are duplicated, not how many duplicates are there
Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface
#include <bits/stdc++.h>
using namespace std;
void menu()
{
cout<<"Menu: "<<endl;
cout<<"1. 1D Math "<<endl;
cout<<"2. Single Dimension Character
Processing "<<endl;
cout<<"3. Two-D Character Processing
"<<endl;
cout<<"4. Exit "<<endl;
cout<<"Choose an option: ";
}
void fillArrayRandomly(int *a,int n,int minimum,int maximum)
{
srand(time(NULL)); //To randomly generate new
values for every run
for(int i=0;i<n;i++)
{
a[i]=
(rand()%(maximum-minimum+1)) + minimum;
}
}
void quicksort(int *arr,int low, int high)
{
int pivot,i,j,temp;
if(low<high)
{
pivot=low;
i=low;
j=high;
while(i<j)
{
while(arr[i]<=arr[pivot]&&i<=high)
i++;
while(arr[j]>arr[pivot]&&j>=low)
j--;
if(i<j)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
temp=arr[j];
arr[j]=arr[pivot];
arr[pivot]=temp;
quicksort(arr,low,j-1);
quicksort(arr,j+1,high);
}
}
void display(int *a,int n)
{
for (int i = 0; i < n; i++)
cout<<a[i]<<" ";
cout<<endl;
}
double average(int a[], int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
sum += a[i];
return (double)sum/(double)n;
}
double median(int a[], int n)
{
if (n % 2 != 0) // check
for odd number of elements
return (double)a[n/2];
return (double)(a[(n-1)/2] + a[n/2])/2.0;
}
int main()
{
int choice; //To store user's input
int n; //Stores size of array
int *a;
int minimum,maximum;
double ave,med;
while(1)
{
menu(); //display menu
to user
cin>>choice;
cout<<endl;
switch(choice)
{
case 1:
cout<<"Enter size
of array: ";
cin>>n;
a= new int[n]; //dynamic
allocation
cout<<"Enter
minimum value: ";
cin>>minimum;
cout<<"Enter
maximum value: ";
cin>>maximum;
fillArrayRandomly(a,n,minimum,maximum); //fill the array with
random values
cout<<"Array
contains: ";
display(a,n); //print the array
quicksort(a,0,n-1);
//sort the array
cout<<"Sorted
array is: ";
display(a,n);
ave=average(a,n);
cout<<"Average is
"<<ave<<endl;
med=median(a,n);
cout<<"Median is
"<<med<<endl;
break;
case 2:
break;
case 3:
break;
case 4:
exit(0); //terminate the program
break;
default: //invalid option
entered Do nothing
cout<<"Invalid
option selected"<<endl;
break;
}
}
return 0;
}
Below is the screenshot of output

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any
NOTE – You may use C++ - but you MAY NOT use #include <string> The goal...
Please note that I cannot use the string library function and that it must be coded in C89, thank you! Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text in the first problem from “Please enter a string of maximum 30 characters:” to “Enter string: ”. Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade. 2.Comments: Header comments...
Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...
hi can you please use simple c++, and write with using "Arrays"
and include "ctype.h, string,iostream" and use "while"
"||&& operators" "for" "if" statements, ,this should be written in
c++101, thanks
Function Return Type Description Return size size size t max_size size t Return maximum size (always match with size) Test whether array is empty bool empty Fill array with value fill void void Exchanges the content of the array by the content of x, which is another array object...
For this assignment you will be creating an array of objects or a list of objects of car parts based on user input. 1. Create a Parts class with the following items a. Properties for PartNum, Part Name, Part Description, and Cost b. Must have a constructor 2. In the main you will need accomplish the following: a. Ask the user how many objects they wish to enter b. Create an array of parts objects c. Loop appropriately to collect...
Please help me to make this c programming code!! Thank
you!!
Concatenation of two strings using pointers Step 1: Ask the user to input ni,n2 and create two character arrays (strings) with ni, n2 size using malloc. Step 2: create a 3rd array using malloc of size(n1+n2). Step 3: Ask the user to input String1 (of size nl) Step 4: Ask the user to input String2 (of size n2) Step 5: concatenate the two arrays and store them in String3...
(you can use any language) Write an algorithm that works with an array of size N and shows the user the next menu: 1. Fill array. 2. Get sum of array elements 3. Get the maximum value of the array elements 4. Get the minimum value of the array elements. 5. Exit
In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....
Write a set of C++ programs to implement the following operations listed in the menu function below. a. File: main.cpp - contains the main function b. File: arrayhw.cpp – contains the 1D array function implementations c. File: arrayhw.h – contains the 1D array function prototyped declarations d. May create other files to implement any other needed function The main menu function should display the following: Main Menu, 1D Array Functions Enter a number to choose one of the following actions:...
Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) { int uniqueDigitCount = 0; int storeDigit = 0; int digit = 0; while (input > 0) { digit = 1 << (input % 10); if (!(storeDigit & digit)) { storeDigit |= digit; ...
**JAVA PLEASE!!**
CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Methods Loops and Conditionals Description The goal of this assignment is for you to produce a simple procedurally generated terrain map out of ASCII character symbols. This will be done through simple probability distributions and arrays Use the following Guideline s: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. User upper case for constants....