Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 282991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:20:08+00:00 2026-05-12T05:20:08+00:00

I was wondering if there is a way to get a date without writing

  • 0

I was wondering if there is a way to get a date without writing your own function. Something such as accessing the date set for the system. I tried

char dateStr[9];
_strdate(dateStr);

with the included time header, but I got compiler error ISO C++ forbids declaration of _strdate with no type. I thought _strdate was already declared and defined in the header so it wouldn’t need a type definition. Could the problem be that I have those 2 lines inside of a struct? Are there any better way to store a date? Thanks.

#include "std_lib_facilities.h"

//Classes-----------------------------------------------------------------------

class Book{
public:
       Book(){}; // default constructor
       //operators
       friend ostream& operator<<(ostream& out, const Book& val);
       bool Book::operator==(const Book& check);
       //member functions
       string title();
       string author();
       string genre();
       int copyright();
       void ISBN();
       bool checkout();
private:
        string title_;
        string author_;
        string genre_;
        int copyright_;
        int ISBN1;
        int ISBN2;
        int ISBN3;
        char ISBN4;
        bool checkout_;
};

class Patron{
public:
       Patron(){}; //default constructor
       //member functions
       string name();
       int libnumber();
       double setfee();
private:
        string name_;
        int libnumber_;
        double libfees;
};

class Library{
public:
       vector<Book> books;
       vector<Patron> patrons;
       struct Transaction{
              Book book;
              Patron patron;};
       vector<Transaction> transactions;
};
// Error Function---------------------------------------------------------------

void _error(const string& s)
{
     cout << endl;
     cout << "Error: " << s << endl;
     cout << endl;
}

// Book Member Functions--------------------------------------------------------

string Book::title()
{
       cout << "Title: ";
       getline(cin,title_);
       cout << endl;
       return title_;
}

string Book::author()
{
       cout << "Author: ";
       getline(cin,author_);
       cout << endl;
       return author_;
}

string Book::genre()
{
       cout << "Genre(Fiction, Nonfiction, Periodical, Biography, Children): ";
       cin >> genre_;
       cout << endl;
       if((genre_!="Fiction")&&(genre_!="Nonfiction")&&(genre_!="Periodical")&&
          (genre_!="Biography")&&(genre_!="Children")) _error("Invalid genre.");
       else return genre_;
}

int Book::copyright()
{
    cout << "Copyright: ";
    cin >> copyright_;
    cout << endl;
    return copyright_;
}

void Book::ISBN()
{
     cout << "ISBN (4 entries. Use spaces): ";
     cin >> ISBN1 >> ISBN2 >> ISBN3 >> ISBN4;
     if((ISBN1<0) || (ISBN2<0) || (ISBN3<0) || (ISBN1>9) || (ISBN2>9) || (ISBN3)>9)
               _error("Must be single digit.");
     else if(!isdigit(ISBN4) && !isalpha(ISBN4))
               _error("Must be single digit or letter.");
     else{ cout << endl;
           return;}
}

bool Book::checkout()
{
     char check;
     cout << "Checked out?(Y or N): ";
     cin >> check;
     switch(check){
     case 'Y':
          cout << endl;
          return true;
          break;
     case 'N':
          cout << endl;
          return false;
          break;
     default: 
              _error("Must be Y or N.");}
}

// Patron Member Functions------------------------------------------------------

string Patron::name()
{
       cout << "Name: ";
       getline(cin,name_);
       cout << endl;
       return name_;
}

int Patron::libnumber()
{
    cout << "Libnumber: ";
    cin >> libnumber_;
    cout << endl;
    return libnumber_;
}

double Patron::setfee()
{
       cout << "Fee due: ";
       cin >> libfees;
       cout << endl;
       return libfees;
}

// Patron Helper Functions------------------------------------------------------

bool isfee()
{
     char isfee_;
     cout << "Does patron have fee due?(Y or N): ";
     cin >> isfee_;
     cout << endl;
     if((isfee_!='Y') && (isfee_!='N')) _error("Must use Y or N.");
     else return(isfee_=='Y');
}

// Operator Overloads-----------------------------------------------------------

ostream& operator<<(ostream& out, const Book& val){
         out << "Title: " << val.title_ << endl;
         out << "Author: " << val.author_ << endl;
         out << "ISBN: " << val.ISBN1 << "-" << val.ISBN2 << "-" << val.ISBN3 << "-" << val.ISBN4 << endl;
         out << endl;
         return out;}

bool Book::operator==(const Book& check){
     return((ISBN1 == check.ISBN1) && (ISBN2 == check.ISBN2) && (ISBN3 == check.ISBN3)
             && (ISBN4 == check.ISBN4));}

// Main Helpers-----------------------------------------------------------------

void runBook()
{
     Library bookstore;
     char notfinished;
     bool bookfinished = false;
     while(!bookfinished)
        {
          Book book;
          book.title();
          book.author();
          book.genre();
          book.copyright();
          book.ISBN();
          book.checkout();
          bookstore.books.push_back(book);
          cout << "Do you wish to store another book?(Y or N): ";
          cin >> notfinished;
          if(notfinished == 'Y'){ 
                         cin.ignore();
                         cout << endl;}
          else if(notfinished == 'N'){
                                       bookfinished = true;
                                       cout << endl;}
          else _error("Must be Y or N");
          }
}

void runPatron()
{
     Library patronstore;
     bool patronfinished = false;
     char notfinished;
     while(!patronfinished)
    {
      Patron patron;
      patron.name();
      patron.libnumber();
      if(isfee()){
                  patron.setfee();}
      cin.ignore();
      runBook(); // Call book function
      patronstore.patrons.push_back(patron);
      cout << "Is there another patron?(Y or N): ";
        cin >> notfinished;
        if(notfinished == 'Y'){ 
                         cin.ignore();
                         cout << endl;}
          else if(notfinished == 'N') patronfinished = true;
          else _error("Must be Y or N");
    }
}

// Main-------------------------------------------------------------------------   

int main()
{    
 runPatron();
     keep_window_open();
}

If you go to class Library and into the Transaction struct, that is where I want to store the date.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:20:09+00:00Added an answer on May 12, 2026 at 5:20 am

    Where to start? Difficult to tell without seeing the code, but here’s some thoughts.

    First, you should probably NOT store the date as a character array within your struct because that will make manipulation of it awkward. Better to store it in it’s native form as a time_t, and convert it to/from strings as required.

    Second, if you must store it as ascii, don’t store it as char[]. You’re just asking for buffer overruns etc. Use string or vector

    However, I think the real answer to your question concerns constructors. If you want Transaction to hold a date, then define it like this

    struct Transaction
    {
       char dateStr[9];
    }
    

    If you want transactions to be datestamped, then assign the date in the constructor

    struct Transaction
    {
       char dateStr[9];
    
       Transaction()
       {
          _strdate(dateStr); // or asctime or whatever
       }
    }
    

    Now, whenever you create a Transaction, it will automatically be filled with the return value from _strdate, whatever that is. Here’s how I’d do it with time_t.

    #include <stdio.h>
    #include <time.h>
    
    struct Transaction
    {
      time_t theTime;
    
      Transaction()
      {
        theTime = time(NULL);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if there is any way to get the lambda expressions that result from
Just wondering if there is any way to get the NS records in C#.
I'm wondering if there is a way to get better information about the location
I was wondering if there is a way to get a list of results
I was wondering if there is a way to get the URL of the
I'm using jQGrid and I'm wondering if there is a way to get the
I was wondering if there was a quick way to get all of an
I was wondering if there was any possible way to get the number (count)
Hi I was wondering if there is any known way to get rid of
I was wondering if there's a way to get event from ajax success? For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.