I have tried a lot of different solutions to this problem and I just can't seem to figure out why the compiler continues to give me this error in my header file. If somebody could please give me some insight, that would be very much appreciated. EDIT: Sorry forgot which line is giving the error. It's in the header file the line: Date(string mstr, int dd, int yy);
And yes I know the this = new Date... is a bad solution, I'm just working it out a bit ;)
Header:
#include <string>
#ifndef DATE_H
#define DATE_H
class Date{
public:
Date(int mm, int dd, int yy);
Date(string mstr, int dd, int yy);
void print();
void printFullDate();
void prompt();
void setMonth(int);
void setDay(int);
void setYear(int);
int getMonth();
int getDay();
int getYear();
static const int monthsPerYear = 12;
private:
int month;
int day;
int year;
int checkDay(int);
};
#endif
And here is the implementation if you need it(It's not totally finished, I'm just trying to test out some of the functions I've written):
#include <iostream>
#include <stdexcept>
#include "Date.h"
using namespace std;
Date::Date(int mm, int dd, int yy){
setMonth(mm);
setYear(yy);
setDay(dd);
}
Date::Date(string mstr, int dd, int yy){
cout << "It's working";
}
int Date::getDay(){
return day;
}
int Date::getMonth(){
return month;
}
int Date::getYear(){
return year;
}
void Date::setDay( int dd ){
day = checkDay(dd);
}
void Date::setMonth( int mm ){
if( mm > 0 && mm <= monthsPerYear)
month = mm;
else
throw invalid_argument("month must be 1-12");
}
void Date::setYear( int yy ){
year = yy;
}
int Date::checkDay( int testDay){
static const int daysPerMonth[ monthsPerYear + 1 ] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if( testDay > 0 && testDay <= daysPerMonth[ getMonth() ])
return testDay;
if( getMonth() == 2 && testDay == 29 && (getYear() % 400 == 0 || ( getYear() % 4 == 0 && getYear() % 100 != 0 ) ) )
return testDay;
throw invalid_argument("Invalid day for current month and year");
}
void Date::print(){
}
void Date::printFullDate(){
}
void Date::prompt(){
int userChoice = 1;
int mm, dd, yy;
string monthStr;
while(userChoice != 3){
cout << "Enter 1 for format: MM/DD/YYYY" << endl;
cout << "Enter 2 for format: Month DD, YYYY" << endl;
cout << "Enter 3 to exit" << endl;
cout << "Choice: " << endl;
cin >> userChoice;
while(userChoice < 1 || userChoice > 3){
cout << "Please enter a number 1 - 3 for the formats above." << endl;
cout << "Choice: " << endl;
cin >> userChoice;
}
if(userChoice != 3){
switch(userChoice){
case 1:
cout << "Enter Month (1 - 12): ";
cin >> mm;
setMonth(mm);
cout << "Enter Day of Month: ";
cin >> dd;
setDay(dd);
cout << "Enter Year: ";
cin >> yy;
setYear(yy);
break;
case 2:
cout << "Enter Month Name: ";
cin >> monthStr;
cout << "Enter Day of Month: ";
cin >> dd;
cout << "Enter Year: ";
cin >> yy;
this = new Date(monthStr, dd, yy);
break;
default:
break;
}
}
}
}
Problem #1: Add an include directive for string
#include <string>
Problem #2: Use the fully qualified std::string rather than just string, or place a using-declaration before your class definition:
using std::string;
Problem #3: You cannot reassign the this pointer:
this = new Date(monthStr, dd, yy); // ERROR!
What you are trying to do should be probably re-written as:
*this = Date(monthStr, dd, yy);
use std::string or declare using namespace std; at the beginning of the code.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Okay so what this program is supposed to do is display the date in M/D/Y format and for some unknown reason it always displays 1/1/1. I have been skimming through this the past 40 mins and still can't understand where I went wrong. Please help me out. Needmorewordstopostthissssssssssssssssssssssssssssssssssssssssssssssss
#include <iostream>
using namespace std;
void displayDate();
class Date{
public:
int month;
int day;
int year;
int mmax;
//functions
int getMonth();
int getDay();
int getYear();
int setMonth();
int setDay();
int setYear();
};
int Date::setMonth(){
int i;
for (i=1; i!=0; i=1)
{
cout << "\n Input the month: ";
cin >> month;
if (month < 1) {
cout << "Please input a valid month";
}
else if (month > 12){
cout << "Please input a valid month";
}
else{
break;
}
}
return month;
}
int Date::setDay(){
int i;
for (i=1; i!=0; i=1)
{
cout << "\n Input the day: ";
cin >> day;
if (day < 1) {
cout << "Please input a valid day";
}
else if ((month == 1 || 3 || 5 || 7 || 8 || 10 || 12) && (day > 31)){
cout << "Please input a valid day";
}
else if ((month == 4 || 6 || 9 || 11) && (day > 30)){
cout << "Please input a valid day";
}
else if ((month == 2) && (day > 28)){
cout << "Please input a valid day";
}
else{
break;
}
}
return day;
}
int Date::setYear(){
int i;
for (i=1; i!=0; i=1)
{
cout << "\n Input the year: ";
cin >> year;
if (year < 1) {
cout << "Please input a valid year";
}
else if (year > 2021){
cout << "Please input a valid year";
}
else{
break;
}
}
return year;
}
int Date::getMonth(){
int month;
return month;
}
int Date::getDay(){
int day;
return day;
}
int Date::getYear(){
int year;
return year;
}
void displayDate(int d,int m, int y){
cout << "Date: " <<m;
cout << "/" <<d;
cout << "/" <<y;
}
main(){
Date x;
int m,d,y;
x.setMonth();
x.setDay();
x.setYear();
m = x.getMonth();
d = x.getDay();
y = x.getYear();
displayDate(d, m ,y);
}
In your code, the getter is not returning the class member variables rather the local variables delared.
int Date::getMonth(){
return month;
}
int Date::getDay(){
return day;
}
int Date::getYear(){
return year;
}
Make the getters like this to return the actual member value.
int Date::getYear(){
int year;
return year;
}
In here, you declare a new int year; variable, that is not initialized, then you return that variable instead of the member variable of your class.
Change it to
int Date::getYear(){
return year;
}
Similar for your other get() functions.
Your conditions are also not working as you want it to:
(month == 1 || 3 || 5 || 7 || 8 || 10 || 12)
doesn't compare month to all those numbers, the numbers just all evaluate to true. The condtion should be:
(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
I have tried to fix a number of problems in your code. And I have added comments explaining why:
#include <iostream>
// using namespace std; // avoid it if you can. It brings too many symbol in main workspace
using std::cout;
using std::cin;
void displayDate();
class Date{
private: // attributes should be private, only accessors should be public (encapsulation)
int month;
int day;
int year;
//int mmax; // comment out member that the code does not (still) use
//functions
public:
int getMonth();
int getDay();
int getYear();
int readMonth(); // setMonth should be a setter: int setMonth(int month) { this->month = month;}
int readDay();
int readYear();
};
int Date::readMonth(){
for (;;) // idiomatic form for an endless loop
{
cout << "\n Input the month: ";
cin >> month;
if (month < 1) {
cout << "Please input a valid month";
}
else if (month > 12){
cout << "Please input a valid month";
}
else{
break;
}
}
return month;
}
int Date::readDay(){
for (;;)
{
cout << "\n Input the day: ";
cin >> day;
if (day < 1) {
cout << "Please input a valid day";
}
else if (day > 31){ // other conditions were useless
cout << "Please input a valid day";
}
else if ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30)){ // fix
cout << "Please input a valid day";
}
else if ((month == 2) && (day > 28)){
cout << "Please input a valid day";
}
else{
break;
}
}
return day;
}
int Date::readYear(){
for (;;)
{
cout << "\n Input the year: ";
cin >> year;
if (year < 1) {
cout << "Please input a valid year";
}
else if (year > 2021){
cout << "Please input a valid year";
}
else{
break;
}
}
return year;
}
int Date::getMonth(){
//int month; // the local variable would hide the member
return month;
}
int Date::getDay(){
//int day;
return day;
}
int Date::getYear(){
//int year;
return year;
}
void displayDate(int d,int m, int y){
cout << "Date: " <<m;
cout << "/" <<d;
cout << "/" <<y;
cout << '\n'; // do not forget end of lines
}
int main(){ // main shall be declared to return int
Date x;
int m,d,y;
x.readMonth();
x.readDay();
x.readYear();
m = x.getMonth();
d = x.getDay();
y = x.getYear();
displayDate(d, m ,y);
return 0; // better to be explicit
}
Other things could be improved, because re-usability is important in OOP. But I am too lazy to go further today ;-)
In my main I have to test the class i made with a for loop but am a little stuck. I have to loop through 3 times and get user input for the ticketing system. I tried making an array and storing the user input but nothing I have tried so far has worked. Im trying to call upon the SetWorkTicket with my loop.
#include<iostream>
#include<iomanip>
#include<stdexcept>
#include<sstream>
using namespace std;
// start of the WorkTicket class
class WorkTicket{
public:
// defailt constructors, if the parameters are not specified the ticket will be set to 0 and the date to 1/1/2000. The rest empty strings
WorkTicket() : myTicketNumber(0), myClientId(""), myDay (1), myMonth (1), myYear(2000), myDescription ("") { }
WorkTicket(int ticketNumber, string clientId, int month, int day, int year, string description);
// mutator method that sets all attributes of the object to the parameters as long as valid. If no problems are being detected set TRUE if not then FALSE.....
bool SetWorkTicket(int ticketNumber, string clientId, int month, int day, int year, string description);
// accessor method that will show all the attributes of the ticket in the console menu
void ShowWorkTicket() const;
// here are the sets and gets for the attributes
// ticket number
void SetTicketNumber(int ticketNumber);
int GetTicketNumber() const {return myTicketNumber;}
// client id
void SetClientId(string clientId) {myClientId = clientId;}
string GetClientId() const { return myClientId;}
// date by day
void SetDay(int day);
int GetDay() const { return myDay; }
// date by month
void SetMonth(int month);
int GetMonth() const { return myMonth; }
// date by year
void SetYear(int year);
int GetYear() const { return myYear; }
// description
void SetDescription(string description) { myDescription = description; }
string GetDescription() const { return myDescription; }
private:
int myTicketNumber;
string myClientId;
int myDay;
int myMonth;
int myYear;
string myDescription;
};
// the work ticket constructor definition
WorkTicket::WorkTicket(int ticketNumber, string clientId, int month, int day, int year, string description)
{
SetTicketNumber(ticketNumber);
SetClientId(clientId);
SetMonth(month);
SetDay(day);
SetYear(year);
SetDescription(description);
}
// set work ticket
bool WorkTicket::SetWorkTicket(int ticketNumber, string clientId, int month, int day, int year, string description)
{
const int MAX_DAY = 31; // setting max day to 31
const int MAX_MONTH = 12; // max month to 12
const int MIN_YEAR = 2000; // the min year 2000 as specified
const int MAX_YEAR = 2099; // max year 2099 as speciified
bool valid = true;
// setting the limits
if(ticketNumber < 0 || month < 1 || month > MAX_MONTH ||
day < 1 || day > MAX_DAY ||
year < MIN_YEAR || year > MAX_YEAR)
valid = false;
else if (clientId.length() < 1 || description.length() < 1)
valid = false;
else
{
myTicketNumber = ticketNumber;
myClientId = clientId;
myDay = day;
myMonth = month;
myYear = year;
myDescription = description;
}
return valid;
}
// this is to show the work ticket, it will show everything in the console..
void WorkTicket::ShowWorkTicket() const
{
cout << "\nWork Ticket Number: " << myTicketNumber
<< "\nClient ID: " << myClientId
<< "\nDate: " << setw(2) << setfill('0') << myMonth
<< "/" << setw(2) << setfill('0') << myDay
<< "/" << myYear
<< "\nIssue: " << myDescription << endl;
}
void WorkTicket::SetTicketNumber(int ticketNumber)
{
if(ticketNumber > 0)
{
myTicketNumber = ticketNumber;
}
else
{
throw invalid_argument("Try Again.");
}
}
// WorkTicket::SetDay definition
void WorkTicket::SetDay(int day)
{
const int MIN_VALID = 1;
const int MAX_VALID = 31;
if(day >= MIN_VALID && day <= MAX_VALID)
{
myDay = day;
}
else
{
throw invalid_argument("Try Again.");
}
}
// WorkTicket::SetMonth definition
void WorkTicket::SetMonth(int month)
{
const int MIN_VALID = 1;
const int MAX_VALID = 12;
if(month >= MIN_VALID && month <= MAX_VALID)
{
myMonth = month;
}
else
{
throw invalid_argument("Try Again.");
}
}
// WorkTicket::SetYear definition
void WorkTicket::SetYear(int year)
{
const int MIN_VALID = 2000;
const int MAX_VALID = 2099;
if(year >= MIN_VALID && year <= MAX_VALID)
{
myYear = year;
}
else
{
throw invalid_argument("Try Again.");
}
}
int main()
{
const int NUMBER_OF_TICKETS = 3;
WorkTicket tickets[NUMBER_OF_TICKETS];
int ticketNumber;
string clientId;
int day;
int month;
int year;
string description;
for (int i = 0; i <NUMBER_OF_TICKETS; i++)
{
cout << "\WorkTicket [" << i << "]: " << endl;
cout << "Enter the ticket number: " << endl;
cout << "Enter the client ID: " << endl;
getline(cin, clientId);
day = SetDay("Enter a day number: ");
}
}
Gather the input and then construct a WorkTicket. Push the tickets into a vector. In the code yet to be written, the newly create WorkTickets can be tested for correctness.
Make sure to include vector at the top of the file.
int main()
{
const int NUMBER_OF_TICKETS = 3;
int ticketNumber;
string clientId;
int day;
int month;
int year;
string description;
std::vector<WorkTicket> tickets;
for (int i = 0; i <NUMBER_OF_TICKETS; i++)
{
cout << "WorkTicket [" << i << "]: " << endl;
cout << "Enter the ticket number: " << endl;
cin>> ticketNumber;
cout << "Enter the client ID: " << endl;
cin >> clientId;
cout << "Enter a day number: " << endl;
cin >> day;
cout << "Enter a month number: " << endl;
cin>> month;
cout << "Enter a year number: " << endl;
cin>> year;
cout << "Enter a description : " << endl;
cin >> description;
try {
tickets.push_back({ticketNumber, clientId, month, day, year, description});
}
catch(std::exception e)
{
std::cout << e.what() << std::endl;
}
}
}
Assuming the rest of your code works correctly and you only have problems in the main:
There are a few issues as commented by others in your code in main:
1) You declared WorkTicket tickets[NUMBER_OF_TICKETS]; but have not used it anywhere.
2) The variable tickets is an array and therefore in the for loop tickets[i] is of type WorkTicket.
3) SetDay is a member function of WorkTicket and takes int as argument.
In light of these, following changes made:
for (int i = 0; i <NUMBER_OF_TICKETS; i++)
{
cout << "\WorkTicket [" << i << "]: " << endl;
cout << "Enter the ticket number: " << endl;
cout << "Enter the client ID: " << endl;
getline(cin, clientId);
cout<<"Enter a day number:";
int day;
cin>>day;
tickets[i].SetDay(day); //day is int and tickets[i] is of WorkTicket
}
Hope this helps to understand the main part better.
/* Program Name: BadDate.cpp
Function: This program determines if a date entered by the user is valid.
Input: Interactive
Output: Valid date is printed or user is alerted that an invalid date was entered
*/
#include <iostream>
bool validateDate(int, int, int);
using namespace std;
int main()
{
// Declare variables
int year;
int month;
int day;
const int MIN_YEAR = 0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31;
bool validDate = true;
This is the work of the housekeeping() method
Get the year, then the month, then the day
int housekeeping() {
cout << "Please enter a year: "<< endl;
cin >> year;
cout << "Please enter a month: "<< endl;
cin >> month;
cout << "Please enter a day: "<< endl;
cin >> day;
}
This is the work of the detailLoop() method
Check to be sure date is valid
int detailLoop() {
if(year <= MIN_YEAR) // invalid year
validDate = false;
else if (month < MIN_MONTH || month > MAX_MONTH) // invalid month
validDate = false;
else if (day < MIN_DAY || day > MAX_DAY) // invalid day
validDate = false;
}
This is the work of the endOfJob() method
test to see if date is valid and output date and whether it is valid or not
int endOfJob()
{
if(validDate == true)
{
// Output statement
cout << " Your date is valid!"<< endl;
}
else
{
// Output statement
cout << " Your date is not valid!"<< endl;
}
}
} // end of main() function
Thank you for taking the time to read my first query. I'm new to C++ and am honestly exhausted. I've spent more time trying to find an IDE that supports "thread" than I have learning the language. Tried DevC++ 5.5.3, Eclipse 4.3.1 and am currently trying Visual Studio Express 2013. I think my code is solid, but of course I could be wrong. More than likely wrong, perhaps. Here's a sample:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <thread>
#include "IntervalSelection.h"
#include "Acnt.h"
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello, Mommy. To begin, what is your name?\n";
char NewMommyName[40];
cin >> NewMommyName;
std::thread t1 (Account()), (NewMommyName));
Supply * pS;
std::time_t NewPumpTime = PumpTime(pS);
struct tm * ptm = std::localtime(&NewPumpTime);
std::chrono::steady_clock::time_point TP =
std::chrono::steady_clock::from_time_t(mktime(ptm));
std::this_thread::sleep_until(TP);
std::cout << " The time is now " << std::put_time (TP, "%X")<<"\nTime to pump!";
t1.join();
//The following errors are generated:
//"no instance of function template "std::put_time" matches the argument list"
//"expression must have class type" (t1.join())
//"expected a ';' - on this line: std::thread t1 (Account()), (NewMommyName));
//"left of '.join' must have class/struct/union"
//"syntax error : ')' - on this line: std::thread t1 (Account()), (NewMommyName));
//error C2040: 'NewMommyName' : 'std::thread' differs in levels of indirection
//from 'char [40]'
There seem to be plenty of folk with a great deal more experience than me who have complaints about finding thread support. Is the error mine or some bug that I can't work around? Is there an IDE I can use that offers less of a headache in this area?
Below is the more consequential of the two header files along with errors that I'm getting when I try to build:
#ifndef ACNT_H
#define ACNT_H
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <thread>
#include "IntervalSelection.h"
using namespace std;
inline
std::string timeString(const std::chrono::steady_clock::time_point& tp)
{
std::time_t t = std::chrono::steady_clock::to_time_t(tp);
std::string ts = ctime(&t);
ts.resize(ts.size() - 1);
return ts;
}
inline
std::chrono::steady_clock::time_point MakeTime(int year, int mon, int day, int
hour, int min, int sec = 0)
{
struct std::tm t;
t.tm_sec = sec;
t.tm_min = min;
t.tm_hour = hour;
t.tm_mday = day;
t.tm_mon = mon - 1;
t.tm_year = year - 1900;
t.tm_isdst = -1;
std::time_t tt = std::mktime(&t);
if (tt == -1){ throw "Not a valid system time."; }
return std::chrono::steady_clock::from_time_t(tt);
}
class Supply
{
friend time_t PumpTime(Supply*);
public:
Supply()
{
double MilkOz = 0.0;
long long tempInterval = 0;
char* dayOrnight;
int year, mon, day, hour, min, sec = 0;
char morning[5] = "a.m.";
char evening[5] = "p.m.";
cout << "\nHow many ounces of milk do you currently have in your
supply?\n";
cout << "For greater accuracy, feel free to enter this value in decimal
form (e.g. 4.5): ";
cin >> MilkOz;
cout << "\nIdeally, how often would you like to pump?\n";
tempInterval = IntervalSelection();
std::chrono::steady_clock::time_point NOW =
std::chrono::steady_clock::now();
time_t currentTp = std::chrono::steady_clock::to_time_t(NOW);
struct tm* local;
local = localtime(¤tTp);
switch (local->tm_hour){ case 12: dayOrnight = evening; break; case 0:
local->tm_hour = (local->tm_hour) + 12; dayOrnight = morning; break; }
if (local->tm_hour > 12){ local->tm_hour = (local->tm_hour) - 12;
dayOrnight = evening;; }
else if (local->tm_hour < 12){ dayOrnight = morning; }
printf("The time is now %d: %d: %d %s", local->tm_hour, local->tm_min,
local->tm_sec, dayOrnight);
cout << "\n";
std::chrono::steady_clock::time_point tNew =
std::chrono::steady_clock::from_time_t(currentTp);
static std::chrono::steady_clock::time_point tt = tNew +
std::chrono::hours(tempInterval);
std::time_t structable, structable2 =
std::chrono::steady_clock::to_time_t(tt);
struct tm* localNew;
localNew = localtime(&structable);
switch (localNew->tm_hour){ case 12: dayOrnight = evening; break; case 0:
localNew->tm_hour = (localNew->tm_hour) + 12; dayOrnight = morning; break; }
if (localNew->tm_hour > 12){ localNew->tm_hour = (localNew->tm_hour) - 12;
dayOrnight = evening; }
else if (localNew->tm_hour < 12){ dayOrnight = morning; }
printf("Your new pump time is scheduled for %d: %d: %d %s",
localNew->tm_hour, localNew->tm_min, localNew->tm_sec, dayOrnight);
cout << "\nTo accept this time enter 'yes'. To specify a different time,
enter 'no'.\n";
char choice[4];
const char* yes = "yes";
const char* no = "no";
cin >> choice;
if (strncmp(choice, yes, 1) == 0)
{
std::string date = ctime(&structable);
date.resize(date.size() - 1);
cout << "Thank you. Your next pump time is confirmed for " << date;
std::time_t tpNewest = structable2;
}
else if (strncmp(choice, no, 1) == 0)
{
cout << "Please enter an exact date to schedule your next pump
time.\n";
cout << "Enter the current year: ";
cin >> year;
cout << "\nEnter a numerical value for the month. For example, the
number one is equivalent to the month of January: ";
cin >> mon;
cout << "\nEnter the numerical day of the month: ";
cin >> day;
cout << "\nEnter the hour: ";
cin >> hour;
cout << "\nEnter the minutes: ";
cin >> min;
static auto tpNew = MakeTime(year, mon, day, hour, min, sec);
cout << "Your next pump time is scheduled for " <<
timeString(tpNew) << endl;
std::time_t tpNewest = std::chrono::steady_clock::to_time_t(tpNew);
}
}
double entry = 0;
double getSupply(double MilkOz, double entry)
{
TotalSupply = MilkOz + entry;
return TotalSupply;
}
~Supply(){}
private:
double TotalSupply;
std::time_t tpNewest;
};
time_t PumpTime(Supply* pS)
{
return pS->tpNewest;
}
class Baby
{
public:
Baby()
{
double lbs = 0.0;
double oz = 0.0;
char pbName[40];
char pbGender[40];
cout << "\nWhat is your Baby's name?" << endl;
cin >> pbName;
strncpy(BabyName, pbName, 40);
cout << "And is " << this->BabyName << " a Boy or a Girl?\n";
cin >> pbGender;
strncpy(BabyGender, pbGender, 5);
if (strncmp(this->BabyGender, "boy", 1) == 0)
{
cout << "\nWhat is his weight in pounds and ounces?\n";
cout << "For example: My baby weighs 16 lbs and 4 oz. \n";
cout << "Pounds: ";
cin >> lbs;
cout << "\n Ounces: ";
cin >> oz;
Baby::getWeight(lbs, oz);
}
else if (strncmp(this->BabyGender, "girl", 1) == 0)
{
cout << "\nWhat is her weight in pounds and ounces?" << endl;
cout << "For example: My baby weighs 16 lbs and 4 oz. \n";
cout << "Pounds: ";
cin >> lbs;
cout << "\nOunces: ";
cin >> oz;
Baby::getWeight(lbs, oz);
}
cout << "\n" << this->BabyName << "'s current weight is " <<
this->BabyWeight << " pounds";
}
double getWeight(double pounds, double ounces)
{
ounces = ounces * 1 / 16;
BabyWeight = pounds + ounces;
return BabyWeight;
}
~Baby(){}
private:
char BabyName[40];
char BabyGender[5];
double BabyWeight;
};
class Mommy
{
public:
Mommy(char* paName)
{
strncpy(MommyName, paName, 40);
}
~Mommy(){}
private:
char MommyName[40];
Baby b;
Supply s;
};
class Account
{
public:
Account(char* paName) :m(paName)
{
strncpy(Name, paName, 40);
}
~Account(){}
private:
char Name[40];
Mommy m;
};
#endif
//ERRORS:
//expression must have class type -t1.join();
//expected a type specifier -std::thread t1 (Account()), (NewMommyName));
//left of '.join' must have class/struct/union
//syntax error : '(' -std::thread t1 (Account()), (NewMommyName));
You have extra parentheses in this line (including an unclosed one):
std::thread t1 (Account()), (NewMommyName));
It should be:
std::thread t1 (Account, (NewMommyName));
Also - your call to std::put_time is incorrect. put_time takes a const std::tm* not time_point. You would need to convert it to a std::tm in order to pass it to put_time
Without the rest of the code, it is hard to diagnose more than those couple of errors. I would suspect your issue is not compiler support.
I'm trying to perform error checking on my initializer value for date, so that a day or month outside the acceptable range will stop the program from debbuging, but I'm getting a debug error even for the acceptable range. I don't know where the error is from, so i posted the code.
// ConsoleApplication56.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<stdexcept>
#include<array>
using namespace std;
class Date
{
public:
explicit Date(int mo, int da, int ye)
{
setDate( mo, da, ye);
}
void setDate(int &m, int &d, int &y)
{
setMonth(m);
setDay(d);
setYear(y);
}
void setMonth(int &m)
{
if (month>0 && month <13)
{
month = m;
}else
throw invalid_argument("month must be 1-12");
}
unsigned int getMonth()const
{
return month;
}
void setDay(int &d)
{
if(day>0 && day<32)
{
day = d;
}else
throw invalid_argument("day must be 0-31");
}
unsigned int getDay()const
{
return day;
}
void setYear(int &y)
{
year = y;
}
unsigned int getYear()const
{
return year;
}
void print()
{
cout<< month <<'/' << day << '/' << year;
}
void nextDay()
{
int numberOfDaysToAdd = 1;
array <int,12> daysInAMonth = {31,28,31,30,31,30,31,31,30,31,30,31};
cout << "the date before is: " << month << "/" << day << "/" << year << endl;
day += numberOfDaysToAdd;
while (day > daysInAMonth [month - 1 ] )
{
day-= daysInAMonth [month - 1 ];
month++;
if (month > 12){
month = 1;
year++;
}
}
cout << "the day after is: " << month << "/" << day << "/" << year << endl;
}
private:
unsigned int month;
unsigned int day;
unsigned int year;
};
int main()
{
char response = 'y';
Date date(12, 3, 2013 );
cout<<"The date is :";
date.print();
cout<<endl;
cout<<endl;
cout<<"do you wish to check the next date(y/n)? :";
cin >> response;
cout<<endl;
while(response == 'y')
{
date.nextDay();
cout<<endl;
cout<<"do you wish to check the next date(y/n)? : ";
cin >> response;
cout<<endl;
}
return 0;
}
You should check the m and d values not the month and day member variables.
void setMonth(int &m)
{
if (month>0 && month <13)
should be
void setMonth(int &m)
{
if (m>0 && m <13)