In: Computer Science
Start by first: Write the code necessary to accept a date in the format (Alice:November,4,2020) and store it in a structure called birthday. (Define the structure, declare the variable, ask the user for input, and store the values in the structure. The month should be a character array, the day and year should be integers.)
Then, Declare a pointer name bdayptr to the type of structure you defined in the previous question. Have the pointer point to the structure you declared, and using the pointer, update the name to the Queen and day to the 31.
C++ Coding Please. Comment in code if you can. thank you!
#include<bits/stdc++.h>
using namespace std;
// coverting month to string format
string Month(int month){
if(month == 1){
return "January";
}
else if(month == 2){
return "February";
}
else if(month == 3){
return "March";
}
else if(month == 4){
return "April";
}
else if(month == 5){
return "May";
}
else if(month == 6){
return "June";
}
else if(month == 7){
return "July";
}
else if(month == 8){
return "August";
}
else if(month == 9){
return "September";
}
else if(month == 10){
return "October";
}
else if(month == 11){
return "November";
}
else{
return "December";
}
}
//defining structure
struct birthday{
string name;
int date;
int month;
int year;
};
int main(){
birthday *ptr, d ;
ptr = &d;
cout << "Enter Name ";
cin >> (*ptr).name;
cout << "Enter Birth date ";
cin >> (*ptr).date;
cout << "Enter Birth Month ";
cin >> (*ptr).month;
cout << "Enter birth year ";
cin >> (*ptr).year;
cout << endl << "Before Update \n" << (*ptr).name << ":" << Month((*ptr).month) << "," << (*ptr).date << "," << (*ptr).year << endl;
// updating name to queen
(*ptr).name = "Queen";
//updating birth date to 31
(*ptr).date = 31;
//printing after update
cout << "After Update \n" << (*ptr).name << ":" << Month((*ptr).month) << "," << (*ptr).date << "," << (*ptr).year << endl;
return 0;
};