Question

In: Computer Science

For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2....

For this assignment you are expected to submit the following two files:

1. ????ℎ??????ℎ??????. ℎ
2. ????ℎ??????ℎ??????. ???

You are being asked to write a class for simple weather data storage. Each instance of the class will hold data for
exactly one month (30 days). Each day’s weather will be classified as either rainy (‘R’), cloudy (‘C’), or sunny (‘S’).
To achieve this, your class will contain a character array of length 30. The class will provide three functions to
return the number of rainy, cloudy, and sunny days in that month.

Name your class "MonthlyWeatherData"; separate declaration from the implementation (i.e. Header and CPP files).
The class has the following members:
1. monthName, a private member of type string
2. arrMonth, a private member array of type char of size 30.
3. Non‐default constructor which receives two parameters, a string and a char array. The constructor will copy the
array’s content from the parameter array to the member variable arrMonth.
4. destructor. Leave the destructor empty.
5. getMonthName, returns the value of the variable monthName
6. numberOfRainyDays, this method returns the number of days in the month designated with the letter R
7. numberOfSunnyDays, this method returns the number of days in the month designated with the letter S
8. numberOfCloudyDays, this method returns the number of days in the month designated with the letter C
9. toVector, this method returns a copy of the array arrMonth in the form of a vector pointer. The method’s return
type is vector*
******Note:******
Use the provided test class to test your implementation. Don not modify this code and do not submit it with
your solution. Your submission should only contain the header and CPP files of the class.
******************

// ***
// Do not modify this file
// ***

#include <iostream>
#include "MonthlyWeatherData.h"

using namespace std;

// ***  Do not modify this file *****


void printStats(const MonthlyWeatherData *monthData) {

   cout << "Status for the month of: " << monthData->getMonthName() << endl;
   cout << " Cloudy Days: " << monthData->numberOfCloudyDays() << endl;
   cout << " Rainy Days: " << monthData->numberOfRainyDays() << endl;
   cout << " Sunny Days: " << monthData->numberOfSunnyDays() << endl;
}

int main() {

   // ***  Do not modify this file *****

   char arr0[] = { 'S', 'S', 'S', 'S', 'S', 'C', 'C', 'C', 'S', 'C', 'R', 'S',
           'R', 'R', 'S', 'S', 'R', 'S', 'S', 'R', 'C', 'C', 'R', 'C', 'C',
           'R', 'R', 'R', 'C', 'C', 'C', 'S', 'S', 'R', 'C', 'R' };
   char arr1[] = { 'R', 'R', 'C', 'R', 'R', 'C', 'C', 'R', 'C', 'S', 'S', 'S',
           'C', 'S', 'S', 'R', 'R', 'C', 'S', 'C', 'C', 'C', 'S', 'S', 'C',
           'C', 'C', 'S', 'S', 'C', 'C', 'C', 'C', 'C', 'C', 'C' };
   char arr2[] = { 'C', 'R', 'C', 'C', 'C', 'C', 'C', 'R', 'S', 'C', 'R', 'R',
           'S', 'S', 'S', 'R', 'R', 'S', 'S', 'S', 'S', 'C', 'S', 'R', 'S',
           'S', 'S', 'R', 'C', 'R', 'S', 'S', 'R', 'R', 'S', 'S' };
   char arr3[] = { 'C', 'C', 'S', 'S', 'R', 'R', 'C', 'C', 'C', 'S', 'R', 'S',
           'C', 'C', 'C', 'C', 'R', 'C', 'R', 'R', 'R', 'R', 'C', 'C', 'R',
           'R', 'S', 'R', 'C', 'C', 'C', 'S', 'R', 'C', 'R', 'R' };

   MonthlyWeatherData *one = new MonthlyWeatherData("January", arr0);
   MonthlyWeatherData *two = new MonthlyWeatherData("February", arr1);
   MonthlyWeatherData *three = new MonthlyWeatherData("March", arr2);
   MonthlyWeatherData *four = new MonthlyWeatherData("April", arr3);

   printStats(one);
   printStats(two);
   printStats(three);
   printStats(four);

   vector<char> *vec = one->toVector();

   cout << "Deallocating MonthlyWeatherData instances" << endl;

   delete one;
   delete two;
   delete three;
   delete four;

   cout << "Weather data for January using vector" << endl;

   for (int i = 0; i < 30; ++i)
       cout << (*vec)[i] << " ";

   cout << endl;

   delete vec;

   return 0;
}

Solutions

Expert Solution

Both required files code are attached below along with the output.

1.MonthlyWeatherData.h

  

#include<iostream>
#include<vector>
using namespace std;

class MonthlyWeatherData {
string monthName;
char arrMonth[30];
public :
MonthlyWeatherData(string m,char *arr){
monthName=m;
for(int i=0; i<30;i++) {
arrMonth[i]=arr[i];
}
}
~MonthlyWeatherData(){
}
string getMonthName ();
int numberOfCloudyDays ();
int numberOfRainyDays ();
int numberOfSunnyDays ();
vector<char> *toVector ();
};


2.MonthlyWeatherData.cpp

// ***
// Do not modify this file
// ***

#include <iostream>
using namespace std;
#include "MonthlyWeatherData.h"

// *** Do not modify this file *****
string MonthlyWeatherData ::getMonthName(){
return monthName;
}
int MonthlyWeatherData ::numberOfCloudyDays() {
int ans=0;
for(int i=0; i< 30; i++) {
if(arrMonth[i]=='C') {
ans++;
}
}
return ans;
}
int MonthlyWeatherData ::numberOfRainyDays() {
int ans=0;
for(int i=0; i< 30; i++) {
if(arrMonth[i]=='R') {
ans++;
}
}
return ans;
}
int MonthlyWeatherData ::numberOfSunnyDays() {
int ans=0;
for(int i=0; i< 30; i++) {
if(arrMonth[i]=='S') {
ans++;
}
}
return ans;
}
vector<char>* MonthlyWeatherData ::toVector(){
vector<char>* temp=new vector<char>();
for(int i=0; i< 30;i++) {
temp->push_back(arrMonth[i]);
}
return temp;
}

void printStats( MonthlyWeatherData *monthData) {

cout << "Status for the month of: " << monthData->getMonthName() << endl;
cout << " Cloudy Days: " << monthData->numberOfCloudyDays() << endl;
cout << " Rainy Days: " << monthData->numberOfRainyDays() << endl;
cout << " Sunny Days: " << monthData->numberOfSunnyDays() << endl;
}

int main() {

// *** Do not modify this file *****

char arr0[] = { 'S', 'S', 'S', 'S', 'S', 'C', 'C', 'C', 'S', 'C', 'R', 'S',
'R', 'R', 'S', 'S', 'R', 'S', 'S', 'R', 'C', 'C', 'R', 'C', 'C',
'R', 'R', 'R', 'C', 'C', 'C', 'S', 'S', 'R', 'C', 'R' };
char arr1[] = { 'R', 'R', 'C', 'R', 'R', 'C', 'C', 'R', 'C', 'S', 'S', 'S',
'C', 'S', 'S', 'R', 'R', 'C', 'S', 'C', 'C', 'C', 'S', 'S', 'C',
'C', 'C', 'S', 'S', 'C', 'C', 'C', 'C', 'C', 'C', 'C' };
char arr2[] = { 'C', 'R', 'C', 'C', 'C', 'C', 'C', 'R', 'S', 'C', 'R', 'R',
'S', 'S', 'S', 'R', 'R', 'S', 'S', 'S', 'S', 'C', 'S', 'R', 'S',
'S', 'S', 'R', 'C', 'R', 'S', 'S', 'R', 'R', 'S', 'S' };
char arr3[] = { 'C', 'C', 'S', 'S', 'R', 'R', 'C', 'C', 'C', 'S', 'R', 'S',
'C', 'C', 'C', 'C', 'R', 'C', 'R', 'R', 'R', 'R', 'C', 'C', 'R',
'R', 'S', 'R', 'C', 'C', 'C', 'S', 'R', 'C', 'R', 'R' };

MonthlyWeatherData *one = new MonthlyWeatherData("January", arr0);
MonthlyWeatherData *two = new MonthlyWeatherData("February", arr1);
MonthlyWeatherData *three = new MonthlyWeatherData("March", arr2);
MonthlyWeatherData *four = new MonthlyWeatherData("April", arr3);

printStats(one);
printStats(two);
printStats(three);
printStats(four);

std::vector<char> *vec = one->toVector();

cout << "Deallocating MonthlyWeatherData instances" << endl;

delete one;
delete two;
delete three;
delete four;

cout << "Weather data for January using vector" << endl;

for (int i = 0; i < 30; ++i)
cout << (*vec)[i] << " ";

cout << endl;

delete vec;

return 0;
}

//output


Related Solutions

There are two programming questions for you to do. Please submit two.s or .asm files. You...
There are two programming questions for you to do. Please submit two.s or .asm files. You can use the usual settings as the previous homework. But if you want to use pseudo-instructions, you will need to uncheck "Bare Machine" and check "Accept Pseudo Instructions" (10 points) Declare an array of integers, something like: . data size : . word 8 array : . word 23 , -12 , 45 , -32 , 52 , -72 , 8 , 13 Write...
you need to submit the following files: Main.java Additionally, you need to download file ‘letter_count.csv’, that...
you need to submit the following files: Main.java Additionally, you need to download file ‘letter_count.csv’, that contains counts for characters in a text (see submission folder on iCollege) and put it into the root of related Eclipse project folder. To view your project folder through system file explorer, right-click on ‘src’ folder in the Eclipse project explorer and choose ‘Show In->System Explorer’. Consider the following Java code, that reads a .csv file: BufferedReader csvReader = new BufferedReader(new FileReader("letter_count.csv")); String currentRow...
In Java: (1) Create two files to submit: ItemToBuy.java - Class definition ShoppingCartDriver.java - Contains main()...
In Java: (1) Create two files to submit: ItemToBuy.java - Class definition ShoppingCartDriver.java - Contains main() method Build the ItemToBuy class with the following specifications: Private fields String itemName - Initialized in the nor-arg constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 No-arg Constructor (set the String instance field to "none") Public member methods (mutators & accessors) setName() & getName() setPrice() & getPrice() setQuantity() & getQuantity() toString()...
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …....
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …. Your Individual Macronutrient Requirements for: Total kcals, Protein, Fat, Carbohydrate & Fiber Completed Diet Report Complete the Report Questions Completing the Diet Report Once you have recorded your 3-day diet, . You can also access the website in the Diet Project Resources module in Canvas. Instructions on how to generate the Cronometer nutrition analysis report can be found in the Diet Project Resources module....
HOMEWORK PROJECT #1 – SHOPPING CART Part I. Create two files to submit: ItemToPurchase.java – Class...
HOMEWORK PROJECT #1 – SHOPPING CART Part I. Create two files to submit: ItemToPurchase.java – Class Definition ShoppingCartPrinter.java – Contains main() method Build the ItemToPurchase class with the following specifications: Specifications Description ItemToPurchase(itemName) itemName – The name will be a String datatype and Initialized in default constructor to “none”. ItemToPurchase(itemPrice) itemPrice – The price will be integer datatype and Initialized in default constructor to 0. ItemToPurchase(itemQuantity) itemQuantity – The quantity will be integer datatype Initialized in default constructor to 0....
JAVA (1) Create two files to submit: Payroll.java - Class definition PayrollClient.java - Contains main() method...
JAVA (1) Create two files to submit: Payroll.java - Class definition PayrollClient.java - Contains main() method Build the Payroll class with the following specifications: 4 private fields String name - Initialized in default constructor to "John Doe" int ID - Initialized in default constructor to 9999 doulbe payRate - Initialized in default constructor to 15.0 doulbe hrWorked - Initialized in default constructor to 40 2 constructors (public) Default constructor A constructor that accepts the employee’s name, ID, and pay rate...
This will be your first collaborative assignment with your team. Your team will submit one 1-2...
This will be your first collaborative assignment with your team. Your team will submit one 1-2 page plan outlining the methods your team will use to work together. Topics such as communications, expectations of team members, and technology use should be covered.
Assignment 1 Note: submit the following 1- "Excel file" include data and graph and analysis "please...
Assignment 1 Note: submit the following 1- "Excel file" include data and graph and analysis "please do not use anything rather than excel" 2- a functional code that performs all the required operations in 1 & part A 1-Collect set of data from the web. About coronavirus evolution in different countries considering other factors like median age of populations, health care systems etc. you are required to perform statistical analysis of this data by calculating the different statistical metrics (like...
For this assignment, please submit the answers to the following questions, as well as an Excel...
For this assignment, please submit the answers to the following questions, as well as an Excel spreadsheet which documents the work you did. Do poets die young? According to William Butler Yeats, “She is the Gaelic muse, for she gives inspiration to those she persecutes. The Gaelic poets die young, for she is restless, and will not let them remain long on earth.” One study designed to investigate this issue examined the age at death for writers from different cultures...
submit the following files: Main.java Consider the following code: import java.util.Scanner; public class Main { public...
submit the following files: Main.java Consider the following code: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String input = ""; System.out.println("Enter the first number: "); input = in.nextLine(); int a = 0; int b = 0; a = Integer.parseInt(input); System.out.println("Enter the second number: "); input = in.nextLine(); b = Integer.parseInt(input); int result = 0; result = a/b; System.out.println("a/b : " + result); } Copy the code to your Main.java file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT