0

Ok so i have a merg sort algorithm in my code yet for some reason its not letting me change it to what I need. Im not seeing where I have the mistake. any help? here are my files along with error. I am trying to sort the events by type which is a char of one letter.

842 M C 20.00 15 2 250 10.00 UC RosebudTheatre 90 One Mike Stand
990 E C 20.00 19 2 1250 10.00 TX TexasHall 75 Maverick Speaker Series
554 C N 16.45 30 1 35 0.00 UC PaloDuraLounge 60 Global Grounds Coffee Hour
318 E C 18.00 3 4 350 0.00 NH 100 75 Engineering Speaker Series
842 M C 20.00 16 4 250 10.00 UC RosebudTheatre 90 One Mike Stand
4 V N 9.00 26 4 2000 0.00 LIB LibraryMall 240 The Big Event
868 M N 10.00 2 4 600 0.00 SAC 108 360 Art Glass Sale
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> 
#include <ctype.h>
#include "UTAevent.h"

void move(UTAevent list1[], int first1, int last1, char list2[], int first2);
void merge( UTAevent lists[], int first1, int last1, int first2, int last2);
void merge_sort(UTAevent to_sort[], int first, int last);

using namespace std;

#define true 1
#define false 0
#define EVENTMAX 10
#define EVENTMIN 0

int main()
{
	int answer;
	int index=0;

	int newnumber, newsize, newlength, newpredict, newmonth, newday, newgoal, newtarget, menu;
	float newcost, newtime, newtotalCost;
	char newbuilding[35], newname[35], newroom[25], newtype, newpurpose;
	char tstr[35];
	int tstrcount = 35;
	enum goal;

	UTAevent Event[EVENTMAX];
	UTAevent TEMP[1];
	FILE *fp;
	std::cout<<
		"\n++++++++++ Event Registry ++++++++++\n\n"
		"This program is built to help the user with\n"
		"sort, searching, and printing school events\n"
		"that are going on around their school, home, or\n"
		"business. Due to limited memory, you are only\n"
		"allowed to have a maximum of 10 events. This\n"
		"will fix this in the next update.\n\n";
	if(( fp = fopen("uta.txt", "r")) == NULL){
		std::cout<<
			"Input file could not be opened!\n";
	}
	while (!feof(fp)){
		fscanf(fp, "%d %c %c %f %d %d %d %f %s %s %d", &newnumber, &newpurpose, &newtype, &newtime, &newday, &newmonth, &newsize, &newcost, &newbuilding, &newroom, &newlength);
		Event[index].fgetline(fp, tstr, tstrcount);
		strcpy(newname, tstr);

		Event[index].set_number(newnumber);
		Event[index].set_purpose(newpurpose);
		Event[index].set_type(newtype);
		Event[index].set_cost(newcost);
		Event[index].set_day(newday);
		Event[index].set_month(newmonth);
		Event[index].set_size(newsize);
		Event[index].set_time(newtime);
		Event[index].set_building(newbuilding);
		Event[index].set_room(newroom);
		Event[index].set_length(newlength);
		Event[index].set_name(newname);
		TEMP[0].set_totalCost(newcost);
		index++;
	}
	menu = true;
	while(menu == true){
		std::cout<< 
			"\n++++++++++++ Main Menu ++++++++++++\n\n"
			"1:\tSort\n"
			"2:\tSearch\n"
			"3:\tPrint the data in the array\n"
			"4:\tEnd the program\n"
			"\n\nPlease choose the number associated with your option.\n";
		cin>>answer;
		if (answer == 1){			// Sort
			std::cout<< 
				"\n++++++++++ Sort the event by ++++++++++\n\n"
				"1:\t\tcode\n"
				"2:\t\tname\n"
				"\n\n Please choose the number associated with your option.\n";
			cin>>answer;
			if (answer == 1){
				merge_sort(Event, 0, index); /**************************************this is my problem, function is at bottom of page****/
			}
			if (answer == 2){
			
			}
			answer =0;
		}
		else if (answer == 2){		// Search
			std::cout<< 
				"\n++++++++ Search for event by ++++++++\n\n"
				"1:\t\tdate\n"
				"2:\t\tpurpose\n"
				"\n\n Please choose the number associated with your option.\n";
			cin>>answer;
			if (answer == 1){
				float charAnswer = TEMP[0].func_Time();
				for(int i = 0; i < EVENTMAX; i++){
					float tempcAnswer = Event[i].get_time();
					if (tempcAnswer == charAnswer){
						printf("\n\tTime found on event %d !\nNumber:%3d\nName:%10s\nMonth:%2d\nDay:%2d\n", i, Event[i].get_number(), Event[i].get_name(), Event[i].get_month(), Event[i].get_day());
					}
					else{
						printf("\nChecking event %d ... \nType not found!\n", i);
					}
				}
			}
			if (answer == 2){
				char floAnswer = TEMP[0].func_Purpose();
				for(int i = 0; i < EVENTMAX; i++){
					char tempfAnswer = Event[i].get_purpose();
					if (tempfAnswer == floAnswer){
						printf("\n\tPurpose found on event %d !\nNumber:%3d\nName:%10s\nMonth:%2d\nDay:%2d\n", i, Event[i].get_number(), Event[i].get_name(), Event[i].get_month(), Event[i].get_day());
					}
					else{
						printf("\nChecking event %d ... \nType not found!\n", i);
					}
				}			
			}
			answer =0;
		}
		else if (answer == 3){		// Print the event
			int count = index;
			int inc;
			printf("num purp type  time  day mnth size cost build             room     length  name \n");
			for (inc = 0; inc < count; inc++){
				printf("%3d %4c %4c %5.2f %4d %4d %4d %5.2f %3s %20s %2d %10s\n", Event[inc].get_number(), Event[inc].get_purpose(), Event[inc].get_type(), Event[inc].get_time(), Event[inc].get_day(), Event[inc].get_month(), Event[inc].get_size(), Event[inc].get_cost(), Event[inc].get_building(), Event[inc].get_room(), Event[inc].get_length(), Event[inc].get_name());
			}
			printf("\nTotal Cost of Events: %f\n", TEMP[0].get_totalCost());
		}
		else if (answer == 4){		// END PROGRAM
			std::cout<<
				"Thank you for using this program!\n";
			menu = false;
		}
	}
	return 0;
}
void merge_sort(UTAevent to_sort[], int first, int last){
	if ( first < last ){
		merge_sort(to_sort, first, (first+last)/2);

		merge_sort(to_sort, (first+last)/2 + 1, last );

		merge( to_sort, first, (first+last)/2, (first+last)/2 + 1, last );
	}
}
void merge( UTAevent lists[], int first1, int last1, int first2, int last2){
	UTAevent temp[10];
	int index, index1, index2;
	int num;

	index = 0;
	index1 = first1;
	index2 = first2;
	num = last1 - first1 + last2 - first2 + 2;

	while ((index1 <= last1) && (index2 <= last2 )){
		if ( lists[index1].get_type() < lists[index2].get_type())
			temp[index++] = lists[index1++];
		else
			temp[index++] = lists[index2++];
	}

	if ( index1> last1)
		move( lists, index2, last2, temp, index);
	else
		move(lists, index1, last1, temp, index);

	move( temp, 0, num-1, lists, first1);
}
void move(UTAevent list1[], int first1, int last1, UTAevent list2[], int first2){
	while (first1 <= last1)
		list2[first2++] = list1[first1++];
}
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> 
#include <ctype.h>
#include "UTAevent.h"

UTAevent::UTAevent()
{
	number = 0;
	type = ' ';
	purpose = ' ';
	time = 00.00;
	day = 0;
	month = 0;
	size = 0;
	cost = 0.00;
	length = 0;
	totalCost = 0.0;
}
void UTAevent::display() const{
	std::cout << "EVENT\n";
}
bool UTAevent::set_totalCost(float tot){
	if (tot >= 0){
		float addcost = tot;
		totalCost = totalCost + tot;
		return true;
	}
	else
		return false;
}
bool UTAevent::set_number(int num){
	int answer = num;
	if (answer == 842 || answer == 110 || answer == 120 || answer == 130 || answer == 140 || answer == 500 || answer == 803 || answer == 810 || answer == 874 || answer == 990 || answer == 318 || answer == 337 || answer == 301 || answer == 554 || answer == 868 || answer == 935 || answer == 4 || answer == 8 || answer == 10){
		number = num;
		return true;
	}
	else
		return false;
}
char UTAevent::set_name(char *nam){
	name[ strlen(nam)+1];
	strcpy(name , nam);
	return true;
}
bool UTAevent::set_type(char typ){
	char charanswer = typ;
	if (charanswer == 'c' || charanswer == 'C'){
		type = 'C';
		return true;
	}
	else if (charanswer == 'S'|| charanswer == 's'){
		type = 'S';
		return true;
	}
	else if (charanswer == 'P'|| charanswer == 'p'){
		type = 'P';
		return true;
	}
	else if (charanswer == 'N'|| charanswer == 'n'){
		type = 'N';
		return true;
	}
	else if (charanswer == 'D'|| charanswer == 'd'){
		type = 'D';
		return true;
	}
	else if (charanswer == 'l'|| charanswer == 'L'){
		type = 'L';
		return true;
	}
	else if (charanswer == 'b'|| charanswer == 'B'){
		type = 'B';
		return true;
	}
	else if (charanswer == 'o'|| charanswer == 'O'){
		type = 'O';
		return true;
	}
	else
		return false;
}
bool UTAevent::set_purpose(char purp){
	char charanswer = purp;
	if (charanswer == 'F' || charanswer == 'f'){
		purpose = 'F';
		return true;
	}
	else if (charanswer == 'm'|| charanswer == 'M'){
		purpose ='M';
		return true;
	}
	else if (charanswer == 'C'|| charanswer == 'c'){
		purpose ='C';
		return true;
	}
	else if (charanswer == 'S'|| charanswer == 's'){
		purpose ='S';
		return true;
	}
	else if (charanswer == 'v'|| charanswer == 'V'){
		purpose ='V';
		return true;
	}
	else if (charanswer == 'l'|| charanswer == 'L'){
		purpose ='L';
		return true;
	}
	else if (charanswer == 'E'|| charanswer == 'e'){
		purpose ='E';
		return true;
	}
	else if (charanswer == 'A'|| charanswer == 'a'){
		purpose ='A';
		return true;
	}
	else if (charanswer == 'O'|| charanswer == 'o'){
		purpose ='O';
		return true;
	}
	else if (charanswer == 'P'|| charanswer == 'p'){
		purpose ='P';
		return true;
	}
	else
		return false;
}
bool UTAevent::set_time(float tim){
	int hrpart = (int)tim;
	int minpart = ((int)(tim*100)%100);
	if ((hrpart <= 24 || hrpart >=0) && (minpart <=60 || minpart >=0)){
		if (hrpart ==24&& minpart==0){
			time = tim;
			return  true;
		}
		else if(hrpart<24)
		{
			time = tim;
			return true;
		}
		else{
			return false;
		}
	}
	else{
		return false;
	}
}
bool UTAevent::set_day(int days){
	if (days < 0 && days >= 31){
		day = days;
		return true;
	}
	return false;
}
bool UTAevent::set_month(int mon){
	if (mon > 0 && mon <= 12){
		month = mon;
		return true;
	}
	return false;
}
bool UTAevent::set_size(int siz){
	if (siz >= 0 ){
		size = siz;
		return true;
	}
	return false;
}
bool UTAevent::set_cost(float cos){
	if (cos >=0 ){
		cost = cos;
		return true;
	}
	return false;
}
char UTAevent::set_building(char *bui){
	building[ strlen(bui) + 1];
	strcpy(building, bui);
	return true;
}
char UTAevent::set_room(char *roo){
	room[ strlen(roo) + 1];
	strcpy(room, roo);
	return true;
}
bool UTAevent::set_length(int len){
	if (len >= 0){
		length = len;
		return true;
	}
	return false;
}
bool UTAevent::set_predict(int pre){
	return true;
}
UTAevent::~UTAevent(void)
{
	delete [] name;
}
int UTAevent::fgetline(FILE *fp, char s[], int lim) {
    char *t;
    int c, len=lim;

    t = s;

    while (--lim>1 && (c=getc(fp)) != EOF && c != '\n')
        *s++ = c;
    if (c == '\n')
        *s++ = c;
    else if (lim == 1) {
	*s++ = '\n';
	fprintf(stderr, "WARNING. fgetline: Line too long, splitted.\n");
    }
    *s = '\0';
    return s - t;
}
char UTAevent::func_Purpose(){															//EVENT PURPOSE
	char answer;
	int k = -1;
	int intAnswer = 0;
	int correct = false;
	while (correct == false){
		printf("Please type in the purpose of the event.\n");
		printf(
			"___Purpose_of_Event___\n"
			"F\tFun and social event.\n"
			"M\tFine arts event; music, dance, art,theatre, \n\tcomedy, and other types of arts activites.\n"
			"C\tCultural; offers support and education related\n\tto a specific culture or group of cultures.\n"
			"S\tSports; opportunities to play or support teams.\n"
			"V\tVolunteer event that does service activities of any\n\t type.\n"
			"L\tLeadership; opportunities for leadership on campus\n\tor learning skills for leadership.\n"
			"E\tEducational; offers some discipline-related content\n\tfor student.\n"
			"A\tAcademic; offers some sort of academic focused\n\tpurpose such as tutoring, mentoring, study group, etc.\n"
			"P\tProfessional; focues on providing suppor to \n\tstudents for future professions.\n"
			"O\tother.\n"
			);
		while (intAnswer < 13)
		{
		  intAnswer = getchar();
		}

		answer = intAnswer;
		if (answer == 'F' || answer == 'f'){
			answer = 'F';
			return answer;
			correct = true;
		}
		else if (answer == 'm'|| answer == 'M'){
			answer = 'M';
			return answer;
			correct = true;
		}
		else if (answer == 'C'|| answer == 'c'){
			answer = 'C';
			return answer;
			correct = true;
		}
		else if (answer == 'S'|| answer == 's'){
			answer = 'S';
			return answer;
			correct = true;
		}
		else if (answer == 'v'|| answer == 'V'){
			answer = 'V';
			return answer;
			correct = true;
		}
		else if (answer == 'l'|| answer == 'L'){
			answer = 'L';
			return answer;
			correct = true;
		}
		else if (answer == 'E'|| answer == 'e'){
			answer = 'E';
			return answer;
			correct = true;
		}
		else if (answer == 'A'|| answer == 'a'){
			answer = 'A';
			return answer;
			correct = true;
		}
		else if (answer == 'O'|| answer == 'o'){
			answer = 'O';
			return answer;
			correct = true;
		}
		else if (answer == 'P'|| answer == 'p'){
			answer = 'P';
			return answer;
			correct = true;
		}
		else{
			printf("\nYou did not enter an accepted event type. Please try again.\n\n");
			return k;
			correct = true;
		}
	}
	return k;
}
float UTAevent::func_Time(){																		//EVENT HOUR AND MINUTE. FIND ANOTHER WAY FOR SINGLE FLOAT. NOT ARRAY
	int hours;
	float answer = 0.0;
	int hrpart = 0;
	int minpart = 0;
	int i;
	int correct = false;
	while (correct == false){
		printf("\n\nPlease type in the number corresponding to the time of day of the event in \nmilitary time.\nThe hour should be on the left while the minutes should be on the right\nof the decimal as so: HH.MM\n");
		scanf("%f", &answer);
		hrpart = (int)answer;
		minpart = ((int)(answer*100)%100);
		if ((hrpart <= 24 || hrpart >=0) && (minpart <=60 || minpart >=0)){
			if (hrpart ==24&& minpart==0){
				return  answer;
				correct = true;
			}
			else if(hrpart<24)
			{
				return answer;
				correct = true;
			}
		}
		else{
			printf("\nYou did not enter an accepted event time. Please try again.\n\n");
			return 0.0;
		}
	}
}
using namespace std;
#ifndef HEADER_FILE_H
#define HEADER_FILE_H

class UTAevent
{
public:
	UTAevent();
	//PRECONDITION: none
	//
	//POSTCONDITION: The data members of the object have
	//				 been initialized to default values.
	~UTAevent();
	//PRECONDITION: none
	//
	//POSTCONDITION: the employee is properly destroyed.
	//
	bool set_number(int num);
	//PRECONDITION: num must be a positive num that is associated with a
	//				specific event.
	//POSTCONDITION: number has been set to num.
	//
	char set_name(char *nam);
	//PRECONDITION: none
	//
	//POSTCONDITION: the name associated with a specific event has been set.
	//
	float func_Time();
	bool set_type(char typ);
	//PRECONDITION: typ must be of one of the specified event types.
	//
	//POSTCONDITION: the character code of the event type has been set.
	//
	bool set_purpose(char purp);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, purp has been added. if
	//				the return value is false, purp was not added.
	bool set_time(float tim);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, tim has been added. if
	//				the return value is false, tim was not added.
	bool set_day(int days);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, days has been added. if
	//				the return value is false, days was not added.
	bool set_month(int mon);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, mon has been added. if
	//				the return value is false, mon was not added.
	bool set_size(int siz);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, siz has been added. if
	//				the return value is false, siz was not added.
	bool set_cost(float cos);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, cos has been added. if
	//				the return value is false, cos was not added.
	char set_building(char *bui);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, *bui has been added. if
	//				the return value is false, *bui was not added.
	char set_room(char *roo);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, roo has been added. if
	//				the return value is false, roo was not added.
	bool set_length(int len);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, len has been added. if
	//				the return value is false, len was not added.
	bool set_predict(int pre);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, pre has been added. if
	//				the return value is false, pre was not added.
	bool set_totalCost(float tot);
	//PRECONDITION: none
	//
	//POSTCONDITION: if the return value is true, tot has been added. if
	//				the return value is false, tot was not added.
	int get_number() const { return number; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event number is returned
	//
	const char * get_name() const { return name; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event name is returned
	//
	char get_type() const { return type; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event type is returned
	//
	char get_purpose() const { return purpose; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event purpose is returned
	//
	float get_time() const { return time; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event time is returned
	//
	int get_day() const { return month; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the day of the event is returned
	//
	int get_month() const { return month; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event month is returned
	//
	int get_size() const { return size; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the event size is returned
	//
	float get_cost() const { return cost; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the cost of the event is returned
	//
	const char * get_building() const { return building; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the building is returned
	//
	const char * get_room()const { return room; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the room number is returned
	//
	int get_length() const { return length; }
	//PRECONDITION: none
	//
	//POSTCONDITION: the length is returned
	//
	int get_predict() const { return predict;}
	//PRECONDITION: none
	//
	//POSTCONDITION: the attendance prediction is returned
	//
	float get_totalCost() const { return totalCost;}
	//PRECONDITION: none
	//
	//POSTCONDITION: the total cost is returned
	//
	void display() const;
	//PRECONDITION: none
	//
	//POSTCONDITION: the id and number in inventory
	//				have been displayed on standard output
	int fgetline(FILE *fp, char s[], int lim);
	//PRECONDITION: none
	//
	//POSTCONDITION: whats left from the line will be stored in a char array
	//				of s with a size of lim.
	char func_Purpose();
	#endif //HEADER_FILE_H
private:
	int number, size, length, predict;
	char name[35];
	unsigned month : 4;
	unsigned day : 5; 
	char room[25];
	char type, purpose; 
	char building[35];
	float cost;
	float time;
	float totalCost;
};
Error	8	error C2664: 'move' : cannot convert parameter 4 from 'UTAevent [10]' to 'char []'	c:\users\tyler\documents\visual studio 2005\projects\lab 4\uta.cpp	168	
Error	9	error C2664: 'move' : cannot convert parameter 4 from 'UTAevent [10]' to 'char []'	c:\users\tyler\documents\visual studio 2005\projects\lab 4\uta.cpp	170	
Error	10	error C2664: 'move' : cannot convert parameter 4 from 'UTAevent []' to 'char []'	c:\users\tyler\documents\visual studio 2005\projects\lab 4\uta.cpp	172
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Atlanticspace
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.