lol. I should spend more time trying things before I post lol... I just put it
getline(cin, name);
and I checked here and you said the same thing. Thanks for all your help.
usafsatwide 0 Newbie Poster
I did that and it works. I only have 1 more problem. I need the program to ask for the employee's name. If the user puts "John Doe" it does not prompt the next question. If they put in "John" it asks for the next question.
#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
#include "ProductionWorker.h"
using namespace std;
using std::string;
int main()
{
string name;
int number;
int date;
int empShift = 0;
double empPayRate = 0.0;
//Create a ProductionWorker object
ProductionWorker stats;
//Get the employee's name
cout << "Enter the employee's name: ";
cin >> name;
//Get the employee's number
cout << "Enter the employee's number: ";
cin >> number;
//Get the date the employee was hired
cout << "Enter the date the employee was hired: ";
cin >> date;
//Get the employee's shift
cout << "Enter the employee's shift where day shift = 1 and night shift = 2: ";
cin >> empShift;
//Get the employee's pay rate
cout << "Enter the employee's pay rate in decimal format (0.00): ";
cin >> empPayRate;
//Store the employee's shift and pay rate into the stats object
stats.setShift(empShift);
stats.setPayRate(empPayRate);
//Define info object and initalize it with values entered
Employee info(name, number, date);
//Display the results
cout << "\nThe employee's name is " << info.getEmployeeName() << endl;
cout << "The employee's number is " << info.getEmployeeNumber() << endl;
cout << "This employee was hired on " << info.getHireDate() << endl;
cout << setprecision(3);
cout << "This worker has the " …
usafsatwide 0 Newbie Poster
main_2.obj : error LNK2005: _main already defined in main_1.obj
EmployeeProductionWorker.exe : fatal error LNK1169: one or more multiply defined symbols found
Do you think I should put everything in the main() function from main_2.cpp into main() in main_1.cpp?
usafsatwide 0 Newbie Poster
I'm retarded lol. I deleted it and I get this:
fatal error LNK1169: one or more multiply defined symbols found
usafsatwide 0 Newbie Poster
main_1.cpp
#include <iostream>
#include <string>
using std::string;
#include "Employee.h"
using namespace std;
int main()
{
string name;
int number;
int date;
Employee info;
//Get the employee's name
cout << "Enter the employee's name: ";
cin >> name;
//Get the employee's number
cout << "Enter the employee's number: ";
cin >> number;
//Get the date the employee was hired
cout << "Enter the date the employee was hired: ";
cin >> date;
//Define info object and initalize it with values entered
Employee info(name, number, date);
//Display the results
cout << "The employee's name is " << info.getEmployeeName() << endl;
cout << "The employee's number is " << info.getEmployeeNumber() << endl;
cout << "This employee was hired on " << info.getHireDate() << endl;
return 0;
}
usafsatwide 0 Newbie Poster
Thanks. That cleared almost all errors I only have two
employeeproductionworker\main_1.cpp(28) : error C2374: 'info' : redefinition; multiple initialization
employeeproductionworker\main_1.cpp(13) : see declaration of 'info'
usafsatwide 0 Newbie Poster
employee.h(10) : error C2146: syntax error : missing ';' before identifier 'employeeName'
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(25) : error C2061: syntax error : identifier 'string'
employee.h(29) : error C2146: syntax error : missing ';' before identifier 'getEmployeeName'
employee.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : warning C4183: 'getEmployeeName': missing return type; assumed to be a member function returning 'int'
employee.h(15) : error C2065: 'employeeName' : undeclared identifier
employee.h(21) : error C2660: 'Employee::set' : function does not take 3 arguments
employee.h(30) : error C2065: 'employeeName' : undeclared identifier
employee.cpp(4) : error C2065: 'string' : undeclared identifier
employee.cpp(4) : error C2146: syntax error : missing ')' before identifier 'name'
employee.cpp(4) : error C2761: 'void Employee::set(void)' : member function redeclaration not allowed
employee.cpp(4) : error C2059: syntax error : ')'
employee.cpp(5) : error C2143: syntax error : missing ';' before '{'
employee.cpp(5) : error C2447: '{' : missing function header (old-style formal list?)
employee.h(10) : error C2146: syntax error : missing ';' before identifier 'employeeName'
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
usafsatwide 0 Newbie Poster
Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
//Employee class declaration
class Employee
{
private:
string employeeName;
int employeeNumber;
int hireDate;
public:
//Default constructor
Employee()
{ employeeName = ' ';
employeeNumber = 0;
hireDate = 0; }
//Constructor
Employee(std::string name, int number, int date)
{ set(name, number, date); }
//Mutator functions
void set(string, int, int);
//Accessor functions
string getEmployeeName() const
{ return employeeName; }
int getEmployeeNumber() const
{ return employeeNumber; }
int getHireDate() const
{ return hireDate; }
};
#endif
Employee.cpp
#include "Employee.h"
#include <string>
void Employee::set(string name, int number, int date)
{
}
ProductionWorker.h
#ifndef PRODUCTIONWORKER_H
#define PRODUCTIONWORKER_H
#include "Employee.h"
#include <string>
class ProductionWorker : public Employee
{
private:
int shift;
double payRate;
public:
//Default constructor
ProductionWorker()
{ shift = 0;
payRate = 0.0; }
//Constructor
ProductionWorker(double p)
{ payRate = p; }
//Mutator functions
void setShift(int s)
{ shift = s; }
void setPayRate(double p)
{ payRate = p; }
//Accessor functions
string getNameShift();
};
#endif
ProductionWorker.cpp
#include "ProductionWorker.h"
#include <string>
string ProductionWorker::getNameShift()
{
string nameShift;
if (shift == 1)
nameShift = "Day";
if (shift == 2)
nameShift = "Night";
return nameShift;
}
main_1.cpp
#include <iostream>
#include <string>
#include "Employee.h"
using namespace std;
int main()
{
string name;
int number;
int date;
Employee info;
cout << "Enter the employee's name: ";
cin >> name;
cout << "Enter the employee's number: ";
cin >> number;
cout << "Enter the date the employee was hired: ";
cin >> date;
info.set(name, number, date);
cout << "The employee's …
usafsatwide 0 Newbie Poster
I tried to put string in place of char on every file and I got a bunch of errors.
usafsatwide 0 Newbie Poster
I'm not sure if you all need all my files, but I'm getting the following error message when compiling:
productionworker.cpp(8) : error C2440: '=' : cannot convert from 'const char [4]' to 'char'
productionworker.cpp(10) : error C2440: '=' : cannot convert from 'const char [6]' to 'char'
Can anyone help?
#include "ProductionWorker.h"
char ProductionWorker::getNameShift()
{
char nameShift;
if (shift == 1)
nameShift = "Day";
if (shift == 2)
nameShift = "Night";
return nameShift;
}
usafsatwide 0 Newbie Poster
Can someone please help me?
I used the DayOfYear object and got this error message:
1>DayOfYear.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const * const DayOfYear::MonthName" (?MonthName@DayOfYear@@2QBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)
1>DayOfYear.obj : error LNK2001: unresolved external symbol "public: static int const * const DayOfYear::MonthDays" (?MonthDays@DayOfYear@@2QBHB)
Thanks everyone for all your help!
My current code is:
#include <iostream>
#include <string>
using namespace std;
//Day of the year class declaration
class DayOfYear
{
private:
public:
static const int MonthDays[];
static const string MonthName[];
void print(int);
};
//**************************************************
// This function displays the month and day using *
// the number entered. *
//**************************************************
void DayOfYear::print(int day)
{
int month = 0;
while (DayOfYear::MonthDays[month] < day)
month = (month + 1) %12;
//Display month and day
cout << DayOfYear::MonthName[month] << " " << day - DayOfYear::MonthDays[month-1];
};
int main()
{
DayOfYear dYear;
//Set days of each month into an array
const int MonthDays[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
//Set the name of each month into an array
const string MonthName[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int day;
//Ask user the total day number
cout << "\nEnter a number you would like to convert into a month and day";
cin >> day;
//Error check for negative numbers and numbers higher than one year
if(day <= 0 || day > 365)
{
cout << "You must enter a valid …
usafsatwide 0 Newbie Poster
pertaining to my code, would I do this?
void DayOfYear::print(int day)
{
int month = 0;
while (DayOfYear::MonthDays[month] < day)
month = (month + 1) %12;
//Display month and day
cout << DayOfYear::MonthName[month] << " " << day - DayOfYear::MonthDays[month-1];
};
usafsatwide 0 Newbie Poster
I am have to create a program for my class. The instructions are to allow a user to input an integer and display the month and day that corresponds to the entered number. For example, user enters 32 and it will display February 1. I must create a DayOfYear class and create a function called print() to display the output message. I am a little lost and need some help. I compile my program and I get the following error message:
dayofyear.cpp(54) : error C2660: 'DayOfYear::print' : function does not take 1 arguments
#include <iostream>
#include <string>
using namespace std;
//Day of the year class declaration
class DayOfYear
{
private:
int day;
public:
static const int MonthDays[];
static const string MonthName[];
void print();
};
//**************************************************
// This function displays the month and day using *
// the number entered. *
//**************************************************
void DayOfYear::print()
{
int month = 0;
while (DayOfYear::MonthDays[month] < day)
month = (month + 1) %12;
//Display month and day
cout << DayOfYear::MonthName[month] << " " << day - DayOfYear::MonthDays[month-1];
};
int main()
{
//Set days of each month into an array
const int MonthDays[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
//Set the name of each month into an array
const string MonthName[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int day;
//Ask user the total day number
cout << "\nEnter a number you would like to convert into a month and day"; …
usafsatwide 0 Newbie Poster
The only problem I had was
void (GetMovieInfo (MovieData &m1, MoviewData &m2)
void (GetMovieInfo (MovieData m1, MovieData m2)
There is also another problem. It display's the movie title with missing the first letter. (ex. entered title is Rush Hour and it displays ush Hour)
#include <iostream>
#include <iomanip>
using namespace std;
const int SIZE = 50;
struct MovieData
{
char title[SIZE];
char director[SIZE];
int year;
int minutesRunning;
};
void GetMovieInfo(MovieData&, MovieData&);
void MovieDisplay(MovieData, MovieData);
int main()
{
MovieData member1, member2;
GetMovieInfo(member1, member2);
MovieDisplay(member1, member2);
return 0;
}
void GetMovieInfo(MovieData &m1, MovieData &m2)
{
cout << "First Movie\n\n";
//Get movie title
cout << "Enter the title of the movie: ";
cin.ignore();
cin.getline(m1.title, SIZE);
//Get director's name
cout << "Enter the Director's name of the movie: ";
cin.ignore();
cin.getline(m1.director, SIZE);
//Get the release year
cout << "Enter the year the movie was released: ";
cin >> m1.year;
//Get the movie runtime in minutes
cout << "Enter runtime of the movie in minutes: ";
cin >> m1.minutesRunning;
cout << "\n---------------------------------\n";
cout << "Second Movie\n\n";
//Get movie title
cout << "Enter the title of the movie: ";
cin.ignore();
cin.getline(m2.title, SIZE);
//Get director's name
cout << "Enter the Director's name of the movie: ";
cin.ignore();
cin.getline(m2.director, SIZE);
//Get the release year
cout << "Enter the year the movie was released: ";
cin >> m2.year;
//Get the movie runtime in minutes
cout << "Enter runtime of the movie in minutes: ";
cin >> m2.minutesRunning;
}
void MovieDisplay(MovieData m1, MovieData m2)
{
cout …
usafsatwide 0 Newbie Poster
I'm in a computer programming class and having trouble. The assignment is:
Write a program that uses a structure named MovieData to store the following information about a movie:
Title
Director
Year Released
Running Time (in minutes)
The program should create two MovieData variables, store values in their members, and pass each one, in turn, to a function that displays the information about the movie in a clearly formatted manner.
I created my program, but getting errors. I guess I don't know exactly what they are asking for. Thanks for any help you can give.
#include <iostream>
#include <iomanip>
using namespace std;
const int SIZE = 50;
struct MovieData
{
char title[SIZE];
char director[SIZE];
int year;
int minutesRunning;
};
void GetMovieInfo(MovieData&);
void MovieDisplay(MovieData);
int main()
{
MovieData member1, member2;
GetMovieInfo(member1, member2);
MovieDisplay(member1, member2);
return 0;
}
void GetMovieInfo(MovieData &m1, &m2)
{
//Get movie title
cout << "Enter the title of the movie: ";
cin.ignore();
cin.getline(m1.title, SIZE);
//Get director's name
cout << "Enter the Director's name of the movie: ";
cin.ignore();
cin.getline(m1.director, SIZE);
//Get the release year
cout << "Enter the year the movie was released: ";
cin >> m1.year;
//Get the movie runtime in minutes
cout << "Enter runtime of the movie in minutes: ";
cin >> m1.minutesRunning;
//Get movie title
cout << "Enter the title of the movie: ";
cin.ignore();
cin.getline(m2.title, SIZE);
//Get director's name
cout << "Enter the Director's name of the movie: ";
cin.ignore();
cin.getline(m2.director, SIZE);
//Get the release …
usafsatwide 0 Newbie Poster
I figured it out LOL. I will post it here for others.
//-------------Start of Program------------->
#include <iostream>
#include <cstdlib>
using namespace std;
//Function Prototype
void stringLength(char *);
void reverseString(char *);
void wordCount(char *);
//----------------Start Main Function------------------->
int main()
{
const int INPUT_SIZE = 100;
char input[INPUT_SIZE];
//Get the user's desired string
cout << "Please enter a phrase or sentence (up to 100 characters): \n\n";
cin.getline(input, INPUT_SIZE); //Read input as a string
//Display number of characters
cout << "\nThe entered string is ";
stringLength(input);
cout << " characters. \n";
//Display string backwards
cout << "The entered string backwards is: ";
reverseString(input);
cout << endl;
//Display number of words in the string
cout << "The number of words in the entered string is: ";
wordCount(input);
cout << "\n\n";
}
//<------------End Main Function----------------------->
//<------------Start String Length Function------------>
void stringLength(char *string1)
{
int stringCount = 0;
stringCount = strlen(string1);
cout << stringCount;
}
//<------------End String Length Function-------------->
//<------------Start Reverse String Function----------->
void reverseString(char *string2)
{
char *revString = string2;
while(*revString != '\0')
++revString;
while (revString != string2)
cout.put(*--revString);
}
//<-----------End Reverse String Function-------------->
//<------------Start Word Count Function----------->
void wordCount(char *string3)
{
int numWords = 1;
while(*string3 != '\0')
{
if(*string3 == ' ')
numWords++;
string3++;
}
cout << numWords;
}
//<-----------End Word Count Function-------------->
usafsatwide 0 Newbie Poster
No it doesn't output anything and windows says it has stopped working.
usafsatwide 0 Newbie Poster
I have to create a word counter function which counts the words of a string. When I run the program, it doesn't end. This is what I have created so far:
//-------------Start of Program------------->
#include <iostream>
#include <cstdlib>
using namespace std;
//Function Prototype
void stringLength(char *);
void reverseString(char *);
void wordCount(char *);
//----------------Start Main Function------------------->
int main()
{
const int INPUT_SIZE = 80;
char input[INPUT_SIZE];
//Get the user's desired string
cout << "Please enter a phrase or sentence: \n\n";
cin.getline(input, INPUT_SIZE); //Read input as a string
//Display number of characters
cout << "\nThe entered string is ";
stringLength(input);
cout << " characters. \n";
//Display string backwards
cout << "The entered string backwards is: ";
reverseString(input);
cout << endl;
//Display number of words in the string
cout << "The number of words in the entered string is: ";
wordCount(input);
cout << endl;
}
//<------------End Main Function----------------------->
//<------------Start String Length Function------------>
void stringLength(char *string1)
{
int stringCount = 0;
stringCount = strlen(string1);
cout << stringCount;
}
//<------------End String Length Function-------------->
//<------------Start Reverse String Function----------->
void reverseString(char *string2)
{
char *revString = string2;
while(*revString != '\0')
++revString;
while (revString != string2)
cout.put(*--revString);
}
//<-----------End Reverse String Function-------------->
//<------------Start Reverse String Function----------->
void wordCount(char *string3)
{
int numWords = 0;
while(string3 != '\0')
numWords++;
cout << numWords;
}
//<-----------End Reverse String Function-------------->