Question 11/. C++ PLEASE
Environment Canada has a program that processes daily temperatures. It includes the variable declarations
given below.
const int MAXDAYS = 100;
double temperatures[MAXDAYS], minTemperature;
int actualDays, longestColdSnapDuration, longestColdSnapStart;
Part I
Part of the program involves finding the lowest temperature. The code is as follows:
minTemperature = findMinimumTemperature (temperatures, actualDays);
cout << "The lowest temperature is " << minTemperature << endl;
Unfortunately the code for function findMinimumTemperature has been lost. Save the day by
writing this function. You should be able to work out everything you need to know.
Part II
The program also deals with cold snaps (one or more consecutive days all having a temperature below -10
degrees). The relevant code is given below:
findLongestColdSnap (temperatures, actualDays,
longestColdSnapDuration,
longestColdSnapStart);
if (longestColdSnapDuration == 0) {
cout << "There were no cold snaps." << endl;
} else {
cout << "The longest cold snap started on day " <<
longestColdSnapStart
<< " and lasted for " << longestColdSnapDuration << "
days." << endl;
}
Function findLongestColdSnap is missing and you must write it as well. If there a number of
equally long cold snaps, any one of them may be chosen as the longest cold snap. As the output is
intended for humans, the first day for which there is temperature data is day one (and not day zero). You
should be able to work out everything else you need to know from the declarations and code supplied.
Here is the required c++ code:
#include <iostream>
using namespace std;
const int MAXDAYS = 100;//required declaration
//function to calculate minimum temperature
double findMinimumTemperature(double *temperatures, int actualDays){
double minTemp = temperatures[0];//set min temp as first day temp
for(int i = 1; i < actualDays; ++i){
minTemp = min(minTemp, temperatures[i]);//if any day has temp smaller that min temp, set min temp to that
return minTemp;
}
//function to find longest cold snap
void findLongestColdSnap(double *temperatures, int actualDays, int &longestColdSnapDuration, int &longestColdSnapStart){
int count = 0;//current streak
int start = -1;//current streak start day
int curStart, curMaxDays = 0;//current maximum streak and start day
for(int i = 0; i < actualDays; ++i){
if(temperatures[i] < -10){
count++; //increment current streak
if(start == -1)start = i;//set current streak start day if not already set
//compare with current maximums streak and update
if(count > curMaxDays){
curMaxDays = count;
curStart = start;
else{
count = 0;
start = -1;
//update final max streak and start day
longestColdSnapDuration = curMaxDays;
longestColdSnapStart = curStart + 1;
}
int main()
{
//required variable declarations
double temperatures[MAXDAYS], minTemperature;
int actualDays, longestColdSnapDuration, longestColdSnapStart;
//input actualDays and temperatures on each day
cout << "Enter the total number of days: ";
cin >> actualDays;
cout << "Enter temperature on each day: ";
for (int i = 0; i < actualDays; ++i)
cin >> temperatures[i];
cout << endl;
//below is the code provided in question
minTemperature = findMinimumTemperature(temperatures, actualDays);
cout << "The lowest temperature is " << minTemperature << endl;
findLongestColdSnap(temperatures, actualDays, longestColdSnapDuration, longestColdSnapStart);
if (longestColdSnapDuration == 0)
cout << "There were no cold snaps." << endl;
else
cout << "The longest cold snap started on day " << longestColdSnapStart << " and lasted for " << longestColdSnapDuration << " days." << endl;
}
Sample IO:
Question 11/. C++ PLEASE Environment Canada has a program that processes daily temperatures. It includes the...
C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...
Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) { // average function , declaring variable int i; char str[40]; float avg = 0; // iterating in...
I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe the missing portion. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. // TicTacToe.cpp: Follow along with...
Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public: static string weekDays[7]; void print() const; string nextDay() const; string prevDay() const; void addDay(int nDays); void setDay(string d); string getDay() const; dayType(); dayType(string d); private: string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...
You can vary it as long as the fahr and cels temperatures line up vertically and everything is clearly labeled. This program involves inputting a set of Fahrenheit temperatures and performing a set of operations on them: The number of temperatures to input is determined by the user at the beginning of the program. You must ask them to enter the number of temperatures that they will be typing in. This number must be between 1 and 30 (inclusive.) If...
The C++ code below will compile but has a variety of runtime issues. Identify a runtime issue with the program and describe how you might fix the problem. #include <iostream> #include <vector> using namespace std; //------------------------------------------------------------------------------ int main() { vector<double> temps; // temperatures double temp = 0; double sum = 0; double high_temp = 0; double low_temp = 0; while (cin >> temp) // read and put into temps temps.push_back(temp); for (int i = 0; i < temps.size(); ++i) {...
I know I'm on the right path, but don't know where to continue from here. This is a C++ assignment Your job is to write that will display a calendar for any given month of a given year. The user will need to type the number of the month as an integer from 1 to 12 (1 is for January, etc.), and the year as a 4-digit integer. This assignment simply requires that your program make use of more than...
Using Embadded C programing Write a program to process a collection of daily high temperatures. Your program should count the number of hot days (high temperature 85 or higher), the number of pleasant days (high temperature 60–84), and the number of cold days (high temperatures less than 60). Test your program on the following data: 55 62 68 74 59 45 41 58 60 67 65 78 82 88 91 92 90 93 87 80 78 79 72 68 61...
This is a C++ question need to complete project 2. attached the completed simple version of the program below but need the updated version which is listed in the project 2 outline Project 2 Rock, Paper, Scissors Updated Take the solution to Lab 3 and make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch....
In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; } while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...