hw6-1 1. Largest/Smallest Array Values Write a program that lets the user enter
ID: 3555956 • Letter: H
Question
hw6-1
1. Largest/Smallest Array Values
Write a program that lets the user enter 10 values into an array. The program should
then display the largest and smallest values stored in the array.
hw6-2
Celsius Temperature Table
The formula for converting a temperature from Fahrenheit to Celsius is
C= 5/9 (F-32)
where F is the Fahrenheit temperature and C is the Celsius temperature. Write a function
named celsius that accepts a Fahrenheit temperature as an argument. The function
should return the temperature, converted to Celsius. Demonstrate the function by
calling it in a loop that displays a table of the Fahrenheit temperatures 0 through 20
and their Celsius equivalents.
hw6-3
Filename: hw6-3.cpp
Write a program that reads in 2 test scores. Wri te a function that will accept the 2 scores. For each score, you should double the score and then add 10. IF the score is over 100, then make it 100. Both scores should be passed back from the function. Your program should work for any number of lines of data.
Part of your program should look like this:
while (cin>>s1>>s2)
{
Explanation / Answer
Dear,
1.
//Header file section
#include<iostream>
using namespace std;
int main()
{
const int size = 10;
int small,large;
int numberArray[size];
//Inputting elements of array
cout<<"Enter Values of array :"<<endl;
for (int i=0;i<size;i++)
{
cin>>numberArray[i];
}
//Assigning starting element to small,large
small=numberArray[0];
large=numberArray[0];
//Logic to find largest and smallest
for(int j=0;j<size;j++)
{
if(numberArray[j] >large)
large = numberArray[j];
if(numberArray[j]<small)
small = numberArray[j];
}
// Displaying the smallest and largest values.
cout<<" The smallest value is:"<<small<<endl;
cout<<" The largest value is :"<<large<<endl;
//To pause system for a while
system("pause");
return 0;
}//End main
2.
//Header file Declartion
#include<iostream>
using namespace std;
//functon prototype
double celsius(double );
void main()
{ //function begins
double F=0,C;//varibles declartion
cout<<"------------------------------"<<endl;
cout<<"Farenheit Celcius"<<endl;
cout<<"------------------------------"<<endl;
for(int i=0;i<=20;i++)
{
C = celsius(F);// function call
cout<<F<<" "<<C<<endl;
F++;
}
//pause system for a while
system("pause");
}//end main
//function definition
double celsius(double F)
{
double temp;
temp = ((5.0/9.0)*(F-32));
return temp;
}//end celsius
5.
//Header file section
#include<iostream>
using namespace std;
//function prototypes
void getScore(int *);
void calAverage(int,int,int,int,int);
int findLowest(int,int,int,int,int);
void main()
{
int score1,score2,score3,score4,score5;
//function call to get scores
//testscore1
getScore(&score1);
//testscore2
getScore(&score2);
//testscore3
getScore(&score3);
//testscore4
getScore(&score4);
//testscore5
getScore(&score5);
//function call to calculate average test score
calAverage(score1,score2,score3,score4,score5);
//pause system for a while
system("pause");
}//end main
//function definitions
//Inputs score
void getScore(int *p)
{
//inputting test score
cout<<"Enter score:";
cin>>*p;
}
//calculates average of scores
void calAverage(int sc1,int sc2,int sc3,int sc4,int sc5)
{
float average;
//function call to find lowest score
int low=findLowest(sc1,sc2,sc3,sc4,sc5);
if(low==sc1)
average=static_cast<float>((sc2+sc3+sc4+sc5)/4);
else if(low==sc2)
average=static_cast<float>((sc1+sc3+sc4+sc5)/4);
else if(low==sc3)
average=static_cast<float>((sc1+sc2+sc4+sc5)/4);
else if(low==sc4)
average=static_cast<float>((sc1+sc2+sc3+sc5)/4);
else
average=static_cast<float>((sc1+sc2+sc3+sc4)/4);
//outputting average of four test scores
cout<<"Average of four test scores:"<<average<<endl;
}//end calAverage
//Returns Lowest among five scores
int findLowest(int sc1,int sc2,int sc3,int sc4,int sc5)
{
if (sc1 <= sc2 && sc1 <= sc3 && sc1 <= sc4 && sc1<=sc5)
{
return sc1;
}
else if (sc2 <= sc1 && sc2 <= sc3 && sc2 <= sc4 && sc2<=sc5)
{
return sc2;
}
else if (sc3 <= sc1 && sc3<=sc2 && sc3 <= sc4 && sc3<=sc5)
{
return sc3;
}
else if (sc4 <= sc1 && sc4 <= sc2 && sc4 <= sc3 && sc4<=sc5)
{
return sc4;
}
else
return sc5;
}//end findLowest
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.