Question

In: Computer Science

Start by first: Write the code necessary to accept a date in the format (Alice:November,4,2020) and...

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!

Solutions

Expert Solution

#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;
};


Related Solutions

Write a java code that first discards as many whitespace characters as necessary until the first...
Write a java code that first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace...
Write a java code that first discards as many whitespace characters as necessary until the first...
Write a java code that first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace...
Please write program in C++ format: Write a program to accept five negative numbers from the...
Please write program in C++ format: Write a program to accept five negative numbers from the user. (1) Find the average of the five numbers and display the answer to the standard output. Keep the answer two decimal points - 5 points (2) Output the numbers in ascending order and display the answer to the standard output. - 5 points
Write a Java code to represent a 1. Date class. As date class is composed of...
Write a Java code to represent a 1. Date class. As date class is composed of three attributes, namely month, year and day; so the class contains three Data Members, and one method called displayDate() which will print these data members. Test the Date class using main class named DateDemo. Create two objects of date class. Initialize the data fields in Date class using the objects, invoke the method displyaDate(). Date month : String year: int day : int displayDate():...
Write a Java console application that reads a string for a date in the U.S. format...
Write a Java console application that reads a string for a date in the U.S. format MM/DD/YYYY and displays it in the European format DD.MM.YYYY  For example, if the input is 02/08/2017, your program should output 08.02.2017
Write a program that prompts the user to enter a date in the format mm/dd/yyyy where...
Write a program that prompts the user to enter a date in the format mm/dd/yyyy where mm is the month , dd is the day and yyyy is a 4 digit year Check if the date is valid by seeing month is between 1 and 12, day is between 1 to 31 and year is between 1800 to 3000. Also check that if month is 2, day is between 1 to 29 If the date is valid then display the...
Java Write a program that will only accept input from a file provided as the first...
Java Write a program that will only accept input from a file provided as the first command line argument. If no file is given or the file cannot be opened, simply print “Error opening file!” and stop executing. A valid input file should contain two lines. The first line is any valid string, and the second line should contain a single integer. The program should then print the single character from the string provided as the first line of input...
Write a query to return the date and day of the week of the first day...
Write a query to return the date and day of the week of the first day of the month two years from today. If today is 10/16/20, then the expect output is 10/01/2022 and the day of the week is thursday. I am using postgresql.
Using pseudocode, write the code that will perform the necessary file operations as described in the...
Using pseudocode, write the code that will perform the necessary file operations as described in the short scenario below: “During registration at a college, student’s details will be captured by a staff member and written to a file called “studentDetails.dat”. The following student details will be captured: name, surname, studentNumber, registeredCourse. The staff member will be prompted for the student details. After every record added to the file, the staff member will be asked whether they would like to add...
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds),...
Write a C++ code that can convert time into hours, minutes, seconds. It can accept (seconds), (minutes, seconds), (hours, minutes, seconds) The input can be written in main It should produce the following output: (67.4, 14, 5) is 67 Hours, 38 Minutes, 5 Seconds (127.86) is 0 Hours, 2 Minutes, 8 Seconds (-3, 73, 2) is -1 Hours, -46 Minutes, -58 Seconds
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT