C++ 1. Write a program that uses an array to find the Average of 10 double value
ID: 3775904 • Letter: C
Question
C++
1.
Write a program that uses an array to find the Average of 10 double values.
Allow the use to enter values for the 10 double numbers. A for loop will facilitate the user input of the 10 random values.
Then use a different for loop to iterate through the array summing the total for all 10 double values.
Output the list of numbers input by user.
Output the average of all the numbers.
Attach Snipping photos of source code and output.
C++
2.
Write a program that allows the user to enter a String and creates a “Ceasar” Cipher encryption of the input. Change each character by 5.
Output the encoded message.
Attach Snipping Photo and source code.
C++
3.
Create an array that holds 1000 random integers between 1-1000.
Allow the user to enter an integer to search.
Output the location of number if it exists in the Array. (Number could appear more than once.)
or
Output number does not exist in the Array.
Explanation / Answer
1.
int main()
{
int count;
double avg;
double arr[count];
cout<<"Enter count"<<endl;
cin>>count;
for(int index=0;index<count;index++)
{
cin>>arr[index];
avgv = avg + arr[index];
}
avg = avg / count;
cout<<"Average is "<<avg;
for(int index=0;index<count;index++)
{
cout<<avg[index]<<" ";
}
}
2.
#include <iostream>
#include <string>
using namespace std;
char ceaserChiper(char);
int main()
{
string str;
do
{
cout << "Enter chiper" << endl;
getline(cin, str);
string out = "";
for (int index = 0; index < str.length(); index++)
{
out += ceaserChiper(str[index]);
}
cout << out << endl;
}
while (!str.length() == 0);
}
char ceaserChiper(char c)
{
if (isalpha(c))
{
c = toupper(c);
c = (((c - 65) + 13) % 26) + 65;
}
return c;
}
3.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int sec, gus;
int arr[1000];
srand ( time(NULL) );
for(int index = 0; index<1000; index++)
{
sec = rand() % 1000 + 1;
arr[index ] = sec;
}
cout<<"Enter a number to find"<<endl;
cin>>gus;
for(int index = 0; index<1000; index++)
{
if(arr[index] == gus)
{
cout<<"Element found at "<<index<<endl;
}
else
{
cout<<"Sorry element doesnt exists";
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.