Programming in C/C++
Program: Use operator overloaded functions for a birthday club – Based on Chapter 11 lecture (25 pts)
Make a class called Birthday that will have a date of month, day, and year and the name.
Need to have overloaded operators to compare values along with regular functions like:
Have a friend function of operator<<:
It will have the prototype of: ostream& operator<<(ostream&, Birthdate&);
With that operator<<, you need to return the ostream& parameter to ensure the output stream works properly.
Then create two functions: sort and search
They will take the array of BirthDate and either sort or search – just regular functions that are NOT part of the BirthDate class (but they do use the overloaded operators).
Main should print your name “birthday club” then create an array of Birthdate, open a data file, and read in the birthdays and name into the array (assume that the name is a single word). Sort the array using the bubblesort and the overloaded operator of > to sort by date. Print the entire array then have a do/while loop that will input a date and search for it (a simple search is fine). Have it print the index if found, else print “not found”. Have it end on negative values.
Create a data file with values such as:
12 15 1988 Mustang Sally
1 31 1967 George Porge
4 7 1992 Nancy Meme
7 9 2001 Tim Breakum
10 23 1978 Markus Mark IV
9 1 1984 Bill Jones
To test the program with.
10 points extra credit, add to the program to template the bubblesort and have a double array of 10 monetary values (cash gifts) random from $1 to $49.99, sort that array also, and print the cash gifts formatted.
// C++ program to create and implement the BirthDate class
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class BirthDate
{
int day,month,year;
string name;
public:
string getName() const;
void setBirthdate(int month, int day, int year, string name);
bool operator==(const BirthDate & other);
bool operator>(const BirthDate &other);
friend ostream& operator<<(ostream& out, const BirthDate &other);
};
// return the name
string BirthDate::getName() const
{
return name;
}
// sets the birthdate and name
void BirthDate::setBirthdate(int month, int day, int year, string name)
{
this->name = name;
this->day = day;
this->month = month;
this->year = year;
}
// returns if 2 birthdate objects are equal
bool BirthDate::operator ==(const BirthDate &other)
{
return(year == other.year && month == other.month && day == other.day);
}
// returns if this date is greater than other date(greater respect to more latest)
bool BirthDate::operator >(const BirthDate &other)
{
if(year > other.year)
return true;
else if(year < other.year)
return false;
else
{
if(month > other.month)
return true;
else if(month < other.month)
return false;
else
{
if(day > other.day)
return true;
else
return false;
}
}
}
ostream& operator<<(ostream &out, const BirthDate &other)
{
out<<other.name.substr(0,other.name.length()-1)<<" : "<<other.month<<"/"<<other.day<<"/"<<other.year;
return out;
}
//end of BirthDate class
void sort(BirthDate birthdays[], int size);
int search(BirthDate birthdays[], int size, BirthDate key);
void sort(double arr[10], int size);
int main() {
cout<<" birthday club "<<endl;
BirthDate birthdays[10]; // create array of max size 10
int size=0;
ifstream fin("birthdate.txt"); // provide the path to the file
int day,month,year;
string name;
if(fin.is_open()) // check if file exists
{
while(!fin.eof()) // loop over the file and create BirthDate objects
{
fin>>month>>day>>year;
getline(fin,name);
birthdays[size].setBirthdate(month,day,year,name);
size++;
}
fin.close();
sort(birthdays,size);
for(int i=0;i<size;i++)
cout<<birthdays[i]<<endl;
do // loop to search for birthdates
{
cout<<" Enter month, day and year values to search(separated by space, negative values to end) : ";
cin>>month>>day>>year;
if(month < 0 || day < 0 || year < 0)
break;
BirthDate key;
key.setBirthdate(month,day,year," ");
int index = search(birthdays,size,key);
if(index < 0)
cout<<" Not found"<<endl;
else
cout<<" Birthdate found at index : "<<index<<endl;
}while(true);
}else
cout<<" File doesn't exists"<<endl;
return 0;
}
// sort the birthdays in ascending order
void sort(BirthDate birthdays[], int size)
{
for(int i=0;i<size-1;i++)
{
for(int j=0;j<size-1-i;j++)
{
if(birthdays[j] > birthdays[j+1])
{
BirthDate temp = birthdays[j];
birthdays[j] = birthdays[j+1];
birthdays[j+1] = temp;
}
}
}
}
// serach for a birthday in the array
int search(BirthDate birthdays[], int size, BirthDate key)
{
for(int i=0;i<size;i++)
{
if(birthdays[i] == key)
return i;
}
return -1;
}
// sort double array of size 10
void sort(double arr[10], int size)
{
for(int i=0;i<size-1;i++)
{
for(int j=0;j<size-1-i;j++)
if(arr[j] > arr[j+1])
{
double temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
//end of program
Output:
Input file:

Output:

Programming in C/C++ Submit your source code files (all .h and .cpp files) NO GLOBAL VARIABLES...
Please include all .cpp/.h files if neccesary, this is in C++ Sort an array of 10,000 elements using the quick sort algorithm as follows: a- sort the array using pivot as the middle element of the array. b- Sort the array using pivot as the median of the fist,last and middle elements of the array . c- sort the array using pivot as the middle element of the array.However ,when the size of any sub list reduces to less than...
C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class...
Please write this code in C++ Object-Oriented Programming,
specify which files are .h, and .cpp, and please add comments for
the whole code.
Include a class diagrams, and explain the approach you used for
the project and how you implemented that, briefly in a few
sentences.
Please note the following:
-Names chosen for classes, functions, and variables should
effectively convey the purpose and meaning of the named
entity.
- Code duplication should be avoided by factoring out common code
into...
(C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...
C++ PRPGRAM- double-linked lists Create the .h and .cpp files for an Element class that contains the data and pointers for a double-link list for this application. Your linked list must consist of objects of this class. The class should contain at least the following elements (you may have more if you wish): The standard four constructors (default, parameterized, copy, move) The standard assignment operators (copy, move) A destructor Stream operators (<< and >>) The standard relational operators (<, <=,...
The
both files are included. Where are these which are colorful.
Point.h and point.cpp
Hor this assignment you are provided the files for a class called point. Download the h and .cpp files and include them in your project. IheじML diagram below details the class Point くくfriend>> ostream& operator.((ostream&, point&) <ごfriend::. İstream& operator:..イ1stream&-point& - : double - v doublc getX) double getYO double - sctX( double): void - set Y(double) : void - point(double-0.0, double-0.0 operator-(const point& bool perator< const...
C++ Project Modify the Date Class: Standards Your program must start with comments giving your name and the name of the assignment. Your program must use good variable names. All input must have a good prompt so that the user knows what to enter. All output must clearly describe what is output. Using the date class, make the following modifications: Make the thanksgiving function you wrote for project 1 into a method of the Date class. It receive the current...
C++ : Please include complete source code in answer This program will have names and addresses saved in a linked list. In addition, a birthday and anniversary date will be saved with each record. When the program is run, it will search for a birthday or an anniversary using the current date to compare with the saved date. It will then generate the appropriate card message. Because this will be an interactive system, your program should begin by displaying a...
C Programming only. (NO C++)
Copy & paste all source code with your answer.
Also take screenshot of it compiled.
11. Write a program with the following software architecture int main) void ReadX/ OuT */ Ant *x) void IncrementX4Times(/t IO */ int *x) void Printx(/*IN */ int x) such that (1) the function ReadX) is called by the function main0 to input the value for main0 variable x from the program user as shown in the screenshot below; (2) IncrementX4Times0...
Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a copy constructor, (6) overload the assignment operator, (7) overload the insertion...