Computer scienceProgramming languagesC++Introduction to STL (Containers and Algorithms)

Basic data structures of STL

Theory

Help Maria

Report a typo

Maria is collecting data on the daily temperatures in her city. She wants to use C++ vectors to keep track of these temperatures. Can you help her create/modify the collectTemperatures and calculateAverage function and to add temperatures to her vector and display the average temperature for the week? Below is the main function for your reference.

int main() {
    
    // Collect daily temperatures using the collectTemperatures function
    std::vector<int> temperatures = collectTemperatures();

    // Calculate the average temperature using the calculateAverage function
    double average = calculateAverage(temperatures);

    // Display the average temperature for the week
    std::cout << "Average temperature for the week: " << average << " degrees Celsius" << std::endl;

    return 0;
}

You can use size method to determine the size of the vector

Sample Input 1:

12 12 12 12 12 12 12

Sample Output 1:

Average temperature for the week: 12 degrees Celsius

Sample Input 2:

24 28 27 27 29 28 26

Sample Output 2:

Average temperature for the week: 27 degrees Celsius
Write a program in C++
std::vector<int> collectTemperatures() {}

double calculateAverage(const std::vector<int>& temperatures) {}

Create a free account to access the full topic