Tuesday, September 22, 2015
Monday, September 14, 2015
Sunday, September 6, 2015
updates and ranting after a weird night.
Life stress dreams has always given me the worst nightmares. With the onset of the new job promotion, the baby on her way, and the research paper deadline looming on the horizon there is no reason to wonder why the nightmares have returned. Yes, my insomnia is still bearing down on me as always. I'm still looking for an alternative to the pharmaceutical zombie inducing meds of late, but they are the only thing keeping me from seeing the sunrise every morning. So what happens in the night? This morning at exactly 3:45am, I sat straight up in bed thinking about how life can be totally random in its path. We are born, grow up, we make some small change in the human existence, we die.
This is my nocturnal life and thought processes from now on it seems.
So what do I do in the ass end of the night? I come down stairs and try to not wake the dogs as I get a glass of water. Yeah, that never really happens as well as one would hope.
If one dog wakes up, they both wake up. If they wake up, they have to pee. Walking the dogs at 4 am is just as sad as it sounds. While just letting them out into the back would be fine but they would just come back inside wet from the grass dew.
Last night as we went past the park at the Library, we passed a lone jogger which made me think, "Who the hell jogs as 4 in the morning?" but then I thought about how he saw Buffy, Murphy, and I "Who the hell walks their dogs at 4 in the morning? What a weirdo". This also led me into thinking about if he had woken up with the same life/death thoughts running through his head and just decided to run it off/
Either way, It 5 am now and the sky is just now starting to show the first purple hues of a fresh dawn on the horizon.
Time to start the new day.
This is my nocturnal life and thought processes from now on it seems.
So what do I do in the ass end of the night? I come down stairs and try to not wake the dogs as I get a glass of water. Yeah, that never really happens as well as one would hope.
If one dog wakes up, they both wake up. If they wake up, they have to pee. Walking the dogs at 4 am is just as sad as it sounds. While just letting them out into the back would be fine but they would just come back inside wet from the grass dew.
Last night as we went past the park at the Library, we passed a lone jogger which made me think, "Who the hell jogs as 4 in the morning?" but then I thought about how he saw Buffy, Murphy, and I "Who the hell walks their dogs at 4 in the morning? What a weirdo". This also led me into thinking about if he had woken up with the same life/death thoughts running through his head and just decided to run it off/
Either way, It 5 am now and the sky is just now starting to show the first purple hues of a fresh dawn on the horizon.
Time to start the new day.
Monday, April 20, 2015
C++ compare two different txt files
//============================================================================
// Name : Dynqueue
// Author : Zachary Standridge
// Version :over a billion
// Copyright : You wouldn't download a car would you?
// Description : opens and compare two different txt files.
//============================================================================#
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "Dynqueue.h"
using namespace std;
int main()
{
//creates an input file stream object
fstream file1 ("file1.txt", ios::in);
//creates another input file stream object
fstream file2 ("file2.txt", ios::in);
//creates two queues to hold characters.
Dynque<char>queue1;
Dynque<char>queue2;
char ch1, ch2;
//read all the characters from file 1 and puts them in queue 1.
file1.get (ch1);
while (!file1.eof())
{
queue1.enqueue(ch1);
file1.get(ch1);
}
//read all the characters from file 2 and puts them in queue 2.
file2.get (ch2);
while (!file2.eof())
{
queue2.enqueue(ch2);
file2.get(ch2);
}
//close
file1.close();
file2.close();
//compare the queues
while(!queue1.isEmpty()&& !queue2.isEmpty())
{
queue1.dequeue(ch1);
queue2.dequeue(ch2);
cout << ch1 << "\t"<< ch2 <<endl;
if (ch1 != ch2)
{
cout << "\nThe files are not identical.\n";
return 0;
}
}
cout <<"\nThe files are identical. \n" << endl << endl;
return 0;
}
----------------------------------------------------------------------------------------------------------------------
---------------------------------------------------.h file------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
#ifndef DYNQUEUE_H_INCLUDED
#define DYNQUEUE_H_INCLUDED
#include <iostream>
using namespace std;
//stock template
template<class T>
class Dynque
{
private:
struct QueueNode
{
T value;
QueueNode *next;
};
QueueNode *front;
QueueNode *rear;
int numItems;
public:
Dynque();
~Dynque();
void enqueue (T);
void dequeue (T &);
bool isEmpty ();
bool isFull ();
void clear ();
};
//empty queue//
template<class T>
Dynque<T>::Dynque()
{
front = NULL;
rear = NULL;
numItems = 0;
}
//deconstructor
template <class T>
Dynque<T>::~Dynque()
{
clear();
}
//Inserts
template <class T>
void Dynque<T>::enqueue (T item )
{
QueueNode*newNode;
//new node
newNode = new QueueNode;
newNode->value = item;
newNode->next = NULL;
//adjust front rear
if (isEmpty())
{
front = newNode;
rear = newNode;
}
else
{
rear->next = newNode;
rear = newNode;
}
//update
numItems++;
}
template <class T>
void Dynque<T>::dequeue(T &item)
{
QueueNode *temp;
if (isEmpty())
{
cout << "The queue is empty.\n";
}
else
{
item = front -> value;
temp = front;
front = front->next;
delete temp;
//update
numItems--;
}
}
template<class T>
bool Dynque<T>::isEmpty()
{
bool status;
if (numItems >0)
status = false;
else
status = true;
return status;
}
template <class T>
void Dynque<T>::clear()
{
T value;
while (!isEmpty())
dequeue(value);
}
#endif // DYNQUEUE_H_INCLUDED
---------------------------------------------------------------------------------------------------------------------
----------------------------------------------file1.txt---------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
The quick brown fox jumps over the lazy dog.
---------------------------------------------------------------------------------------------------------------------
----------------------------------------------file2.txt---------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
'I never forget a face, but in your case I’d be glad to make an exception.'
------------------------------------------------------------------------------------------------------------------------
create all files in the same folder, compile the cpp and enjoy
// Name : Dynqueue
// Author : Zachary Standridge
// Version :over a billion
// Copyright : You wouldn't download a car would you?
// Description : opens and compare two different txt files.
//============================================================================#
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "Dynqueue.h"
using namespace std;
int main()
{
//creates an input file stream object
fstream file1 ("file1.txt", ios::in);
//creates another input file stream object
fstream file2 ("file2.txt", ios::in);
//creates two queues to hold characters.
Dynque<char>queue1;
Dynque<char>queue2;
char ch1, ch2;
//read all the characters from file 1 and puts them in queue 1.
file1.get (ch1);
while (!file1.eof())
{
queue1.enqueue(ch1);
file1.get(ch1);
}
//read all the characters from file 2 and puts them in queue 2.
file2.get (ch2);
while (!file2.eof())
{
queue2.enqueue(ch2);
file2.get(ch2);
}
//close
file1.close();
file2.close();
//compare the queues
while(!queue1.isEmpty()&& !queue2.isEmpty())
{
queue1.dequeue(ch1);
queue2.dequeue(ch2);
cout << ch1 << "\t"<< ch2 <<endl;
if (ch1 != ch2)
{
cout << "\nThe files are not identical.\n";
return 0;
}
}
cout <<"\nThe files are identical. \n" << endl << endl;
return 0;
}
----------------------------------------------------------------------------------------------------------------------
---------------------------------------------------.h file------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
#ifndef DYNQUEUE_H_INCLUDED
#define DYNQUEUE_H_INCLUDED
#include <iostream>
using namespace std;
//stock template
template<class T>
class Dynque
{
private:
struct QueueNode
{
T value;
QueueNode *next;
};
QueueNode *front;
QueueNode *rear;
int numItems;
public:
Dynque();
~Dynque();
void enqueue (T);
void dequeue (T &);
bool isEmpty ();
bool isFull ();
void clear ();
};
//empty queue//
template<class T>
Dynque<T>::Dynque()
{
front = NULL;
rear = NULL;
numItems = 0;
}
//deconstructor
template <class T>
Dynque<T>::~Dynque()
{
clear();
}
//Inserts
template <class T>
void Dynque<T>::enqueue (T item )
{
QueueNode*newNode;
//new node
newNode = new QueueNode;
newNode->value = item;
newNode->next = NULL;
//adjust front rear
if (isEmpty())
{
front = newNode;
rear = newNode;
}
else
{
rear->next = newNode;
rear = newNode;
}
//update
numItems++;
}
template <class T>
void Dynque<T>::dequeue(T &item)
{
QueueNode *temp;
if (isEmpty())
{
cout << "The queue is empty.\n";
}
else
{
item = front -> value;
temp = front;
front = front->next;
delete temp;
//update
numItems--;
}
}
template<class T>
bool Dynque<T>::isEmpty()
{
bool status;
if (numItems >0)
status = false;
else
status = true;
return status;
}
template <class T>
void Dynque<T>::clear()
{
T value;
while (!isEmpty())
dequeue(value);
}
#endif // DYNQUEUE_H_INCLUDED
---------------------------------------------------------------------------------------------------------------------
----------------------------------------------file1.txt---------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
The quick brown fox jumps over the lazy dog.
---------------------------------------------------------------------------------------------------------------------
----------------------------------------------file2.txt---------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
'I never forget a face, but in your case I’d be glad to make an exception.'
create all files in the same folder, compile the cpp and enjoy
Linked List
//============================================================================
// Name : Employee.cpp
// Author : Zachary Standridge
// Version :over a billion
// Copyright : You wouldn't download a car would you?
// Description : Create and organize a list
//============================================================================
#include <iostream>
using namespace std;
struct node
{
int number;
node *next;
};
bool isEmpty(node *head);
char menu();
void insertAsFirstElement(node *&head, node *&last, int number);
void insert(node *&head, node *&last, int number);
void remove(node *&head, node *&last);
void showList(node *current);
bool isEmpty(node *head)
{
if(head == NULL)
return true;
else
return false;
}
char menu()
{
char choice;
cout <<"Menu\n";
cout <<"------------------\n";
cout <<"1. Add Number\n";
cout <<"2. Remove Number\n";
cout <<"3. Show List\n";
cout <<"4. Exit\n";
cin >> choice;
return choice;
}
void insertAsFirstElement(node *&head, node *&last, int number)
{
node *temp = new node;
temp ->number = number;
temp ->next = NULL;
head = temp;
last = temp;
}
void insert(node *&head, node *&last, int number)
{
if(isEmpty(head))
insertAsFirstElement(head,last,number);
else
{
node *temp = new node;
temp ->number = number;
temp ->next = NULL;
last ->next = temp;
last = temp;
}
}
void remove(node *&head, node *&last)
{
if (isEmpty(head))
cout<<"There is nothing here\n";
else if (head == last)
{
delete head;
head == NULL;
last == NULL;
}
else
{
node *temp = head;
head = head->next;
delete temp;
}
}
void showList(node *current)
{
if(isEmpty(current))
cout<< "The list is empty.\n";
else
{
cout << "The list contains : \n";
while (current != NULL)
{
cout << current -> number << endl;
current = current->next;
}
}
}
int main ()
{
node *head = NULL;
node *last = NULL;
char choice;
int number;
do
{
choice = menu ();
switch(choice)
{
case '1': cout<< "Please enter a number;";
cin>>number;
insert(head, last,number);
break;
case '2': remove (head, last);
break;
case '3': showList(head);
break;
default: cout<< "System exit\n";
}
}
while(choice != '4');
return 0;
}
// Name : Employee.cpp
// Author : Zachary Standridge
// Version :over a billion
// Copyright : You wouldn't download a car would you?
// Description : Create and organize a list
//============================================================================
#include <iostream>
using namespace std;
struct node
{
int number;
node *next;
};
bool isEmpty(node *head);
char menu();
void insertAsFirstElement(node *&head, node *&last, int number);
void insert(node *&head, node *&last, int number);
void remove(node *&head, node *&last);
void showList(node *current);
bool isEmpty(node *head)
{
if(head == NULL)
return true;
else
return false;
}
char menu()
{
char choice;
cout <<"Menu\n";
cout <<"------------------\n";
cout <<"1. Add Number\n";
cout <<"2. Remove Number\n";
cout <<"3. Show List\n";
cout <<"4. Exit\n";
cin >> choice;
return choice;
}
void insertAsFirstElement(node *&head, node *&last, int number)
{
node *temp = new node;
temp ->number = number;
temp ->next = NULL;
head = temp;
last = temp;
}
void insert(node *&head, node *&last, int number)
{
if(isEmpty(head))
insertAsFirstElement(head,last,number);
else
{
node *temp = new node;
temp ->number = number;
temp ->next = NULL;
last ->next = temp;
last = temp;
}
}
void remove(node *&head, node *&last)
{
if (isEmpty(head))
cout<<"There is nothing here\n";
else if (head == last)
{
delete head;
head == NULL;
last == NULL;
}
else
{
node *temp = head;
head = head->next;
delete temp;
}
}
void showList(node *current)
{
if(isEmpty(current))
cout<< "The list is empty.\n";
else
{
cout << "The list contains : \n";
while (current != NULL)
{
cout << current -> number << endl;
current = current->next;
}
}
}
int main ()
{
node *head = NULL;
node *last = NULL;
char choice;
int number;
do
{
choice = menu ();
switch(choice)
{
case '1': cout<< "Please enter a number;";
cin>>number;
insert(head, last,number);
break;
case '2': remove (head, last);
break;
case '3': showList(head);
break;
default: cout<< "System exit\n";
}
}
while(choice != '4');
return 0;
}
Thursday, April 2, 2015
Employee (Amended) This time it checks for shift number, pay rate, and employee number
#include <iostream>
#include <string>
using namespace std;
class Employee
{
private:
string employeeName;
int employeeNumber;
string hireDate;
//member function to validate the E number
void checkEmployeeNumber()
{
if (employeeNumber < 0 ||employeeNumber > 9999 )
throw invalidEmployeeNumber();
}
public:
//exception class
class invalidEmployeeNumber
{};
//constructors
Employee (string name, int number, string hDate)
{
//set variables
employeeName = name;
employeeNumber = number;
hireDate = hDate;
//check the employee number
checkEmployeeNumber();
}
//mutators
void setEmployeeName (string name)
{
employeeName=name;
}
void setEmployeeNumber (int number)
{
employeeNumber=number;
checkEmployeeNumber();
}
void setHireDate (string hDate)
{
hireDate = hDate;
}
//accessors
string getEmployeeName() const
{
return employeeName;
}
int getEmployeeNumber() const
{
return employeeNumber;
}
string getHireDate () const
{
return hireDate;
}
};
class ProductionWorker:
public Employee
{
private:
int shift;
double hourlyPayRate;
//member function checking shift number
void checkShift()
{
if
(shift < 1 || shift > 2)
throw InvalidShift();
}
// checking pay rate
void checkPayRate()
{
if
(hourlyPayRate < 0)
throw InvalidPayRate();
}
public:
//exception class
class InvalidShift
{};
class InvalidPayRate
{};
//constructors
ProductionWorker (string name, int number, string hDate, int shiftNum, double payRate):
Employee (name, number, hDate)
{
//set the member variables
shift = shiftNum;
hourlyPayRate = payRate;
//check the shift and pay rate
checkShift();
checkPayRate();
}
//mutators
void setShift (int shiftNum)
{
shift = shiftNum;
checkShift();
}
void setHourlyPayRate (double payRate)
{
hourlyPayRate = payRate;
checkPayRate();
}
//accessors
int getShift () const
{
return shift;
}
double getHourPayRate()
{
return hourlyPayRate;
}
};
//prototype
void testValues (string, int, string, int, double);
int main()
{
//test good data
cout <<" Testing good data....\n";
testValues("Pedro Colon", 1234, "12/01/2000",1,550.00);
//test bad shift number
cout <<"\n Testing bad shift number....\n";
testValues("Pedro Colon", 1234, "12/01/2000",9,550.00);
//test bad employee number
cout <<"\n Testing bad employee number....\n";
testValues("Pedro Colon", 91234, "12/01/2000",1,550.00);
//test bad pay rate
cout <<"\n Testing bad pay rate ....\n";
testValues("Pedro Colon", 1234, "12/01/2000",1,-550.00);
return 0;
}
void testValues (string name, int number, string hDate, int shift, double payRate)
{
try
{
ProductionWorker (name, number, hDate, shift, payRate);
//good stuff
cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
cout<<"\n Good data\n" ;
}
catch (ProductionWorker::invalidEmployeeNumber)
{
cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
cout<<"\nInvalid Employee Number encountered \n";
}
catch (ProductionWorker::InvalidShift)
{
cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
cout<<"\nInvalid Shift Number encountered \n";
}
catch (ProductionWorker::InvalidPayRate)
{
cout <<"Employee Name- "<< name<< " \nEmployee #- \t"<< number<< " \nHire Date- \t"<<hDate<<" \nShift # -\t "<<shift<< " \nPay Rate\t"<<payRate<<endl;
cout<<"\nInvalid Pay Rate encountered \n";
}
}
Tuesday, March 17, 2015
Employee and productionWorker c++
#include <string>
#include <iostream>
using namespace std;
//-----------------------------------------------------------------//
//-------------------------class employee--------------------------//
//-----------------------------------------------------------------//
class Employee
{
private: string empName;
int empNum;
string hireDate;
public:
Employee():empName(""),empNum(0), hireDate("") //default ctor
{}
Employee(string name, int num, string date)
{
empName = name;
empNum = num;
hireDate = date;
}
void setempName(string n);
void setempNum(int nm);
void setHiredate(string d);
string getName();
int getNum();
string getDate();
void print();
};
void Employee::setempName(string n)
{empName = n ;}
void Employee::setempNum(int nm)
{empNum = nm;}
void Employee::setHiredate(string d)
{hireDate = d;}
string Employee::getName()
{return empName;}
int Employee::getNum()
{return empNum;}
string Employee::getDate()
{return hireDate;}
//-----------------------------------------------------------------//
//--------------------class production worker----------------------//
//-----------------------------------------------------------------//
class ProductionWorker : public Employee
{
private:
int shift;
double hrlyPay;
public:
ProductionWorker():shift(0) , hrlyPay(0.0)
{}
ProductionWorker(int sh , double pay)
{
shift = sh;
hrlyPay = pay;
}
void setshift(int s);
void setPay(double p);
int getshift();
double getPay();
void print();
};
void ProductionWorker::print()
{
cout << "Employee Name: " << getName() << endl;
cout << "Employee Number: " << getNum() << endl;
cout << "Hire Date: " << getDate() << endl;
cout << "Shift: " << getshift();
if(shift == 1)
{
cout << "(Day Shift)" << endl;}
else
cout << "(Night Shift)" << endl;
cout << "Pay Rate: $" << getPay()<< endl;
}
void ProductionWorker::setshift(int sh)
{sh = shift;}
void ProductionWorker::setPay(double p)
{p = hrlyPay;}
int ProductionWorker::getshift()
{return shift;}
double ProductionWorker::getPay()
{return hrlyPay;}
//-----------------------------------------------------------------//
//-------------------------Main------------------------------------//
//-----------------------------------------------------------------//
int main()
{
int Shift;
double pay;
cout << "Enter 1 for Day Shift or 2 for Night Shift: "<<endl;
cout<< "Any deviation will default to Night Shift ";
cin >> Shift;
cout << "Enter hourly pay: $";
cin >> pay;
ProductionWorker emp1(Shift, pay);
emp1.setempName("Pedro, Colon");
emp1.setempNum(8675309);
emp1.setHiredate("1-1-2000");
emp1.print();
return 0;
}
Saturday, February 21, 2015
c++ date conversion
//============================================================================
// Name : Assignment.cpp
// Author : Zachary Standridge
// Version :over a billion
// Copyright : You wouldn't download a car would you?
// Description : convert simple entered dates into week number and Semester with year at the end.
//============================================================================
#include <iostream>
#include <cmath>
#include <string>
#include <stdio.h>
using namespace std;
class week
{
int month;
int day;
int year;
public:
week (int month = 1, int day = 1, int year = 1,int weekNum = 0,int semesterNum = 1,
double week = 0, double ineedthisnum = 0, double thisonetoo =0 )
{
week::month = month;
week::day = day;
week::year = year;
};
void showWeek();
~week(){}
};
int main()
{
int month;
int day;
int year;
//--------------------------------month----------------------------------
cout<<"Enter Date"<<endl;
cout << "Enter month (between 1 and 12)" << endl;
cin >> month;
if
(month > 12 || month < 1)
{
month = 1;
}
//--------------------------------day----------------------------------
cout << "Enter day (between 1 and 31)" << endl;
cin >> day;
if
(day > 31 || day < 1)
{
day = 1;
}
//--------------------------------year----------------------------------
cout << "Enter year (between 1900 and 2030)"<< endl;
cin >> year;
if
(year > 2030 || year < 1900)
{
year = 1900;
}
week newDate(month, day, year);
//==================================Week=================================
double week = 0.00000;
double ineedthisnum = 0.00000;
{
week = day ;
//cout<<" Week #----------> " << week<<endl;
ineedthisnum = month;
ineedthisnum = ineedthisnum * 29.6041667; //converts months to days
ineedthisnum = ineedthisnum - 29.604; //sets January to adding 0 days
week = ineedthisnum + week; //adds days to months(days)
// cout<<" Week #----------> " << week<<endl;
week = week / 365; //days divided by days in the year
//cout<<" Week #----------> " << week<<endl;
week = week * 52; //Converts to weeks in a year
//cout<<" Week #----------> " << week<<endl;
week = ceil(week); //rounds up
}
//cout<<" Week #----------> " << week<<endl;
//==================================Semester=============================
double thisonetoo = 0;
int semesterNum;
//cout<<""<< "month"<<month<<endl;
thisonetoo = month;
//converts months to temp value
//cout<<""<< thisonetoo<<endl;
thisonetoo = thisonetoo / 12; //percentage of the year past
//cout<<""<< thisonetoo<<endl;
thisonetoo = thisonetoo * 3; //numbers of semesters
//cout<<""<< thisonetoo<<endl;
thisonetoo = round(thisonetoo);
if ( thisonetoo <=0 ) //back up for low numbers
{
thisonetoo = thisonetoo + 1;
}
else
{
thisonetoo = thisonetoo*1;
}
semesterNum = static_cast<int>(thisonetoo);
//cout<<" semester #----------> " << semesterNum<<endl;
//be sure to commented out all the couts while watching the data being changed.
//=======================================================================
//cout<<"\n\n"<<month<<"/"<<day<<"/"<<year<<"\n is"<<endl;
// required output ------------------Week 5, Spring 2015
//cout<<"Week "<< week<<endl;
//cout<<"Semester "<< semesterNum<<endl;
if (semesterNum == 1)
cout<<"Week "<< week<<", Spring " << year<< endl;
else if (semesterNum == 2)
cout<<"Week "<< week<<", Summer " << year<< endl;
else if (semesterNum == 3)
cout<<"Week "<< week<<", Fall " << year<< endl;
else
cout<<"Something has gone seriously wrong!"<< endl;
return 0;
}
// Name : Assignment.cpp
// Author : Zachary Standridge
// Version :over a billion
// Copyright : You wouldn't download a car would you?
// Description : convert simple entered dates into week number and Semester with year at the end.
//============================================================================
#include <iostream>
#include <cmath>
#include <string>
#include <stdio.h>
using namespace std;
class week
{
int month;
int day;
int year;
public:
week (int month = 1, int day = 1, int year = 1,int weekNum = 0,int semesterNum = 1,
double week = 0, double ineedthisnum = 0, double thisonetoo =0 )
{
week::month = month;
week::day = day;
week::year = year;
};
void showWeek();
~week(){}
};
int main()
{
int month;
int day;
int year;
//--------------------------------month----------------------------------
cout<<"Enter Date"<<endl;
cout << "Enter month (between 1 and 12)" << endl;
cin >> month;
if
(month > 12 || month < 1)
{
month = 1;
}
//--------------------------------day----------------------------------
cout << "Enter day (between 1 and 31)" << endl;
cin >> day;
if
(day > 31 || day < 1)
{
day = 1;
}
//--------------------------------year----------------------------------
cout << "Enter year (between 1900 and 2030)"<< endl;
cin >> year;
if
(year > 2030 || year < 1900)
{
year = 1900;
}
week newDate(month, day, year);
//==================================Week=================================
double week = 0.00000;
double ineedthisnum = 0.00000;
{
week = day ;
//cout<<" Week #----------> " << week<<endl;
ineedthisnum = month;
ineedthisnum = ineedthisnum * 29.6041667; //converts months to days
ineedthisnum = ineedthisnum - 29.604; //sets January to adding 0 days
week = ineedthisnum + week; //adds days to months(days)
// cout<<" Week #----------> " << week<<endl;
week = week / 365; //days divided by days in the year
//cout<<" Week #----------> " << week<<endl;
week = week * 52; //Converts to weeks in a year
//cout<<" Week #----------> " << week<<endl;
week = ceil(week); //rounds up
}
//cout<<" Week #----------> " << week<<endl;
//==================================Semester=============================
double thisonetoo = 0;
int semesterNum;
//cout<<""<< "month"<<month<<endl;
thisonetoo = month;
//converts months to temp value
//cout<<""<< thisonetoo<<endl;
thisonetoo = thisonetoo / 12; //percentage of the year past
//cout<<""<< thisonetoo<<endl;
thisonetoo = thisonetoo * 3; //numbers of semesters
//cout<<""<< thisonetoo<<endl;
thisonetoo = round(thisonetoo);
if ( thisonetoo <=0 ) //back up for low numbers
{
thisonetoo = thisonetoo + 1;
}
else
{
thisonetoo = thisonetoo*1;
}
semesterNum = static_cast<int>(thisonetoo);
//cout<<" semester #----------> " << semesterNum<<endl;
//be sure to commented out all the couts while watching the data being changed.
//=======================================================================
//cout<<"\n\n"<<month<<"/"<<day<<"/"<<year<<"\n is"<<endl;
// required output ------------------Week 5, Spring 2015
//cout<<"Week "<< week<<endl;
//cout<<"Semester "<< semesterNum<<endl;
if (semesterNum == 1)
cout<<"Week "<< week<<", Spring " << year<< endl;
else if (semesterNum == 2)
cout<<"Week "<< week<<", Summer " << year<< endl;
else if (semesterNum == 3)
cout<<"Week "<< week<<", Fall " << year<< endl;
else
cout<<"Something has gone seriously wrong!"<< endl;
return 0;
}
Saturday, January 31, 2015
MovieData
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
#include <iostream>
#include <string>
using namespace std;
struct MovieData
{
string m, n, o, p;
MovieData (string, string, string, string);
};
//Make a constructor
MovieData::MovieData (string a, string b, string c, string d) {
m = a;
n = b;
o = c;
p = d;
}
void printinfo (MovieData Q)
{
cout<<"Title: "<<Q.m<<endl;
cout<<"Director: "<<Q.n<<endl;
cout<<"Year Released: "<<Q.o<<endl;
cout<<"Writer: "<<Q.p<<endl;
}
int main()
{
string title;
string direct;
string yearR;
string writer;
//title
std::cout << "Enter title of movie:\n";
std::getline(std::cin, title);
//director
std::cout << "Enter the Director of movie:\n";
std::getline(std::cin, direct);
//year
std::cout << "Enter the year movie was released:\n";
std::getline(std::cin, yearR);
//writer
std::cout << "Enter writer of the screenplay:\n";
std::getline(std::cin, writer);
MovieData movie1(title, direct, yearR, writer);
//=====================================================//
//title
std::cout << "Enter title of movie:\n";
std::getline(std::cin, title);
//director
std::cout << "Enter the Director of movie:\n";
std::getline(std::cin, direct);
//year
std::cout << "Enter the year movie was released:\n";
std::getline(std::cin, yearR);
//writer
std::cout << "Enter writer of the screenplay:\n";
std::getline(std::cin, writer);
MovieData movie2(title, direct, yearR, writer);
//i know this could be done in a loop...//
//===========================================================//
//Call function to Display the results.
cout<<"\n\nHere is the Movie Data:\n";
cout<<"Movie 1:";
cout<<"\n-----------------------\n";
printinfo (movie1);
cout<<"\n\nMovie 2:";
cout<<"\n-----------------------\n";
printinfo (movie2);
return 0;
}
their members, and pass each one, in turn, to a function that displays the
information about the movie in a clearly formatted manner
#include <iostream>
#include <string>
using namespace std;
struct MovieData
{
string m, n, o, p;
MovieData (string, string, string, string);
};
//Make a constructor
MovieData::MovieData (string a, string b, string c, string d) {
m = a;
n = b;
o = c;
p = d;
}
void printinfo (MovieData Q)
{
cout<<"Title: "<<Q.m<<endl;
cout<<"Director: "<<Q.n<<endl;
cout<<"Year Released: "<<Q.o<<endl;
cout<<"Writer: "<<Q.p<<endl;
}
int main()
{
string title;
string direct;
string yearR;
string writer;
//title
std::cout << "Enter title of movie:\n";
std::getline(std::cin, title);
//director
std::cout << "Enter the Director of movie:\n";
std::getline(std::cin, direct);
//year
std::cout << "Enter the year movie was released:\n";
std::getline(std::cin, yearR);
//writer
std::cout << "Enter writer of the screenplay:\n";
std::getline(std::cin, writer);
MovieData movie1(title, direct, yearR, writer);
//=====================================================//
//title
std::cout << "Enter title of movie:\n";
std::getline(std::cin, title);
//director
std::cout << "Enter the Director of movie:\n";
std::getline(std::cin, direct);
//year
std::cout << "Enter the year movie was released:\n";
std::getline(std::cin, yearR);
//writer
std::cout << "Enter writer of the screenplay:\n";
std::getline(std::cin, writer);
MovieData movie2(title, direct, yearR, writer);
//i know this could be done in a loop...//
//===========================================================//
//Call function to Display the results.
cout<<"\n\nHere is the Movie Data:\n";
cout<<"Movie 1:";
cout<<"\n-----------------------\n";
printinfo (movie1);
cout<<"\n\nMovie 2:";
cout<<"\n-----------------------\n";
printinfo (movie2);
return 0;
}
Friday, December 12, 2014
Math C++
Write a C++ program that creates the following functions:
double Max (double Values[], int size);
double Min (double Values[], int size);
double calc Average(double Values[], int size);
double calc Median(double Values[], int size);
double calc Standard Deviation (double Values[], int size);
Write a driver program that creates an array with 11 values and calculates all of the preceding values. Display the values to the user. Create a second array that has 10 values and display all of the preceding values.
Note: You do not need to get input from the user. Must use the previous functions prototype.
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
double calcMax (int arg[], int length)
{
int maxValue = 0;
for(int i = 0; i < length; i++)
{
if(arg[i] > maxValue)
{
maxValue = arg[i];
}
}
cout << "The highest value is: " << maxValue<<endl;
}
double calcMin (int arg[], int length)
{
int minValue = 1000;
for(int i = 0; i < length; i++)
{
if(arg[i] < minValue)
{
minValue = arg[i];
}
}
cout << "The minimum value is: " << minValue<<endl;
}
double calcAverage (int arg[], int length)
{
int sum=0;
for (int i=0; i<length; i++)
sum += arg[i];
cout << "The average value is: " << sum/length<<endl;
}
double calcMedian (int arg[], int length)
{
sort(arg, arg + length);
cout << "The new sorted array looks like this." << endl;
cout << "=====================================" << endl;
for (size_t i = 0; i != length; ++i)
cout << arg[i] << " ";
{ double* dpSorted = new double[length];
for (int i = 0; i < length; ++i) {
dpSorted[i] = arg[i];
}
for (int i = length - 1; i > 0; --i) {
for (int j = 0; j < i; ++j) {
if (dpSorted[j] > dpSorted[j+1]) {
double dTemp = dpSorted[j];
dpSorted[j] = dpSorted[j+1];
dpSorted[j+1] = dTemp;
}
}
}
double dMedian = 0.0;
if ((length % 2) == 0) {
dMedian = (dpSorted[length/2] + dpSorted[(length/2) - 1])/2.0;
} else {
dMedian = dpSorted[length/2];
}
delete [] dpSorted;
cout << " " << endl;
cout << "The median value is: " << dMedian<<endl;
}
}
double calcStandardDev (int arg[], int length)
{
double deviation;
double sum2;
double mean;
for ( int i = 0; i <=length; i++ )
{
sum2 += pow((arg[i]-mean),2);
}
deviation= sqrt(sum2/(length-1));
cout << "The Standard Deviation is : " <<deviation<<endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
}
int main ()
{
int number1 [] = {1,2,3,4,25,6,7,8,9,11,12};
calcMax(number1, 11);
calcMin(number1, 11);
calcAverage(number1,11);
calcMedian(number1, 11);
calcStandardDev(number1,11);
int number2 [] ={10,9,8,7,6,5,4,3,2,1,11};
calcMax(number2, 10);
calcMin(number2, 10);
calcAverage(number2,10);
calcMedian(number2, 10);
calcStandardDev(number2,10);
return 0;
}
double Max (double Values[], int size);
double Min (double Values[], int size);
double calc Average(double Values[], int size);
double calc Median(double Values[], int size);
double calc Standard Deviation (double Values[], int size);
Write a driver program that creates an array with 11 values and calculates all of the preceding values. Display the values to the user. Create a second array that has 10 values and display all of the preceding values.
Note: You do not need to get input from the user. Must use the previous functions prototype.
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
double calcMax (int arg[], int length)
{
int maxValue = 0;
for(int i = 0; i < length; i++)
{
if(arg[i] > maxValue)
{
maxValue = arg[i];
}
}
cout << "The highest value is: " << maxValue<<endl;
}
double calcMin (int arg[], int length)
{
int minValue = 1000;
for(int i = 0; i < length; i++)
{
if(arg[i] < minValue)
{
minValue = arg[i];
}
}
cout << "The minimum value is: " << minValue<<endl;
}
double calcAverage (int arg[], int length)
{
int sum=0;
for (int i=0; i<length; i++)
sum += arg[i];
cout << "The average value is: " << sum/length<<endl;
}
double calcMedian (int arg[], int length)
{
sort(arg, arg + length);
cout << "The new sorted array looks like this." << endl;
cout << "=====================================" << endl;
for (size_t i = 0; i != length; ++i)
cout << arg[i] << " ";
{ double* dpSorted = new double[length];
for (int i = 0; i < length; ++i) {
dpSorted[i] = arg[i];
}
for (int i = length - 1; i > 0; --i) {
for (int j = 0; j < i; ++j) {
if (dpSorted[j] > dpSorted[j+1]) {
double dTemp = dpSorted[j];
dpSorted[j] = dpSorted[j+1];
dpSorted[j+1] = dTemp;
}
}
}
double dMedian = 0.0;
if ((length % 2) == 0) {
dMedian = (dpSorted[length/2] + dpSorted[(length/2) - 1])/2.0;
} else {
dMedian = dpSorted[length/2];
}
delete [] dpSorted;
cout << " " << endl;
cout << "The median value is: " << dMedian<<endl;
}
}
double calcStandardDev (int arg[], int length)
{
double deviation;
double sum2;
double mean;
for ( int i = 0; i <=length; i++ )
{
sum2 += pow((arg[i]-mean),2);
}
deviation= sqrt(sum2/(length-1));
cout << "The Standard Deviation is : " <<deviation<<endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
}
int main ()
{
int number1 [] = {1,2,3,4,25,6,7,8,9,11,12};
calcMax(number1, 11);
calcMin(number1, 11);
calcAverage(number1,11);
calcMedian(number1, 11);
calcStandardDev(number1,11);
int number2 [] ={10,9,8,7,6,5,4,3,2,1,11};
calcMax(number2, 10);
calcMin(number2, 10);
calcAverage(number2,10);
calcMedian(number2, 10);
calcStandardDev(number2,10);
return 0;
}
Tuesday, December 2, 2014
C++ Pay problem
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Program Description:Write a program that calculates the daily //
////pay and total pay of a person who works for a penny the first //
//day and their pay doubles every day after that. The program must //
// calculate the salary and not just output the pay. Use the //
// following variables: //
// //
// Input: days worked //
// Processing: pay cubed + running total //
// Output: pay grid of money earned //
///////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int days, maxValue = 0;
float wages = 0;
float totalpay = 0;
float runningtotal = 0;
cout <<"Please enter the number of days worked: ";
cin >> maxValue;
cout << "Day \t\tPay \t\tTotal Pay" <<endl;
cout <<"----------------------------------------" <<endl;
for (days = 1; days <= maxValue; days++)
{
if (days==1)
{
wages = .01;
runningtotal = wages;
totalpay = .01;
}
else if (days==2)
{
wages = wages + .01;
runningtotal = wages;
totalpay = .03;
}
else
{
wages = ((wages) * (2));
runningtotal = wages;
totalpay = wages + runningtotal -.01;
}
cout <<days<<"\t\t"<<wages<<"\t\t"<< totalpay<< endl;
}
return 0;
}
Subscribe to:
Posts (Atom)