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...
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 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
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.
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
Using the first code of this lab (Figure 1), write a code that displays the status...
Using the first code of this lab (Figure 1), write a code that displays the status of a push button on the LCD, that is, when you press it you should see “Pushed” on the LCD and when you release it, you should see “Released” #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2);...
Write the Java source code necessary to build a solution for the problem below: Create a...
Write the Java source code necessary to build a solution for the problem below: Create a MyLinkedList class. Create methods in the class to add an item to the head, tail, or middle of a linked list; remove an item from the head, tail, or middle of a linked list; check the size of the list; and search for an element in the list. Create a test class to use the newly created MyLinkedList class. Add the following names in...
Write the Java source code necessary to build a solution for the problem below: Create a...
Write the Java source code necessary to build a solution for the problem below: Create a MyLinkedList class. Create methods in the class to add an item to the head, tail, or middle of a linked list; remove an item from the head, tail, or middle of a linked list; check the size of the list; and search for an element in the list. Create a test class to use the newly created MyLinkedList class. Add the following names in...
Write the Java source code necessary to build a solution for the problem below: The Fibonacci...
Write the Java source code necessary to build a solution for the problem below: The Fibonacci numbers form a sequence where each number is the sum of the previous two numbers. Starting from 0 and 1, the first eight Fibonacci numbers are built in the following list using the equation Fn = Fn-1 + Fn-2: 0, 0 0, 1 1, 1 1, 2 2, 3 3, 5 5, 8 8, 13 The sequence would be the numbers in red (0,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT