-can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h
-I attached my program and the example out put.
-Must use Cstring not string
-Use strcpy
- use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name)
- the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp
- I also attached some requirements below as a picture
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>
using namespace std;
const int ARRAY_SIZE = 100;
const int STR_SIZE = 250;
struct Tasks
{
int day, year, month, number;
char name[STR_SIZE + 1], desc[STR_SIZE + 1];
};
void printUpdateMenu()
{
cout << "\n";
cout << "********** Main Manu**********" << endl;
cout << "1 - PRINT ALL TASKS: " << endl;
cout << "2 - PRINT TASKS IN DATE RANGE: " << endl;
cout << "3 - COMPLETE A TASK: " << endl;
cout << "4 - ADD TASK: " << endl;
cout << "5 - QUIT: " << endl;
}
void printMenu()
{
cout << "\n";
cout << "********** Main Manu**********" << endl;
cout << "1 - PRINT ALL TASKS: " << endl;
cout << "2 - PRINT TASKS IN DATE RANGE: " << endl;
cout << "3 - COMPLETE A TASK: " << endl;
cout << "4 - ADD TASK: " << endl;
cout << "5 - QUIT: " << endl;
}
int getChoice(int a, int b)
{
int ch;
cout << "Enter choice: ";
cin >> ch;
cin.ignore(STR_SIZE, '\n');
cout << endl;
while((ch < a)||(ch > b))
{
cout << "not a valid choice. please re-enter" << endl;
cin >> ch;
cin.ignore();
}
return ch;
}
int readData(Tasks tasks[], int &count)
{
ifstream infile("tasks.txt");
char ch = infile.peek();
while (!infile.eof() && ch != '\n')
{
cout << endl;
infile.getline(tasks[count].name, STR_SIZE);
infile.getline(tasks[count].desc, STR_SIZE);
infile >> tasks[count].month;
infile >> tasks[count].day;
infile >> tasks[count].year;
infile >> tasks[count].number;
infile.ignore(STR_SIZE, '\n');
count++;
}
infile.close();
return count;
}
void printall(Tasks tasks[], int count)
{
for (int i = 0; i < count ; i++)
{
cout << "name: " << tasks[i].name << endl;
cout << "desc: " << tasks[i].desc << endl;
cout << "due: " << tasks[i].month << "/" << tasks[i].day
<< "/" << tasks[i].year << endl;
if (tasks[i].number == 0)
{
cout << "The task is not complited" << endl;
}
else if (tasks[i].number == 1)
{
cout << "The task is complited" << endl;
}
}
}
void printtasksindaterange(Tasks tasks[], int count)
{
int year, month, day, year1, month1, day1;
cout << "Begin Date: "<< endl;
cout << "Enter year (2017 - 2067): ";
cin>> year;
if (year < 2017 || year > 2067)
{
cout << "Invalid year. Please Re-enter: ";
cin >> year;
}
cout << "Enter month (1 - 12): ";
cin>> month;
if (month <= 0 || month > 12)
{
cout << "Invalid month. Please Re-enter: ";
cin >> month;
}
cout << "Enter date (1 - 31): ";
cin>> day;
if (day <= 0 || day > 31)
{
cout << "Invalid day. Please Re-enter: ";
cin >> day;
}
cout << "Enter due year (2017 - 2067): ";
cin>> year1;
if (year1 < 2017 || year1 > 2067)
{
cout << "Invalid year. Please Re-enter: ";
cin >> year1;
}
cout << "Enter due month (1 - 12): ";
cin>> month1;
if (month1 <= 0 || month1 > 12)
{
cout << "Invalid month. Please Re-enter: ";
cin >> month1;
}
cout << "Enter due date (1 - 31): ";
cin>> day1;
if (day1 <= 0 || day1 > 31)
{
cout << "Invalid day. Please Re-enter: ";
cin >> day1;
}
int date1 = year*10000 + month*100 + day;
int date2 = year1*10000 + month1*100 + day1;
for (int i = 0; i < count; i++)
{
int k = tasks[i].year*10000 + tasks[i].month*100 + tasks[i].day;
if(k <= date2 && k >= date1 )
{
cout << "name: " << tasks[i].name << endl;
cout << "desc: " << tasks[i].desc << endl;
cout << "due: " << tasks[i].month << "/" << tasks[i].day
<< "/" << tasks[i].year << endl;
cout << "number: " << tasks[i].number << endl;
}
}
}
void completeatask(Tasks tasks[], int count)
{
bool found = false;
char name[STR_SIZE];
cout << "Enter Name: "<< endl;
cin.getline(name, STR_SIZE, '\n');
for (int i = 0; i < count; i++)
{
cout<< "*" << tasks[i].name << "******"<<endl;
cout<< "*" << name<< "*" <<endl;
if(strcmp(tasks[i].name, name) == 0)
{
tasks[i].number = 1;
cout << "the task cs162 project 2 has been completed." << endl;
found = true;
}
}
if(!found)
{
cout<< " Invalid name"<< endl;
}
}
void addtask(Tasks tasks[], int &count)
{
if(count >= ARRAY_SIZE)
{
cout << "no more room in inventory" << endl;
return;
}
char name[STR_SIZE], desc[STR_SIZE];
int year, month, day, number;
cout << "Enter Name: "<< endl;
cin.getline(name, STR_SIZE, '\n');
cout << "Enter Description (All On One Line): " << endl;
cin.getline(desc, STR_SIZE, '\n');
cout << "Entering Due Date: " << endl;
cout << "Enter month (1 - 12): ";
cin >> month;
if (month <= 0 || month > 12)
{
cout << "Invalid month. Please Re-enter: ";
cin >> month;
}
cout << "Enter day (1 - 31): ";
cin >> day;
if (day <= 0 || day > 31)
{
cout << "Invalid day. Please Re-enter: ";
cin >> day;
}
cout << "Enter year (2017 - 2067): ";
cin >> year;
if (year < 2017 || year > 2067)
{
cout << "Invalid year. Please Re-enter: ";
cin >> year;
}
cout << "Enter a number: " << endl;
cin >> number;
strcpy(tasks[count].name,name);
strcpy(tasks[count].desc,desc);
tasks[count].month = month;
tasks[count].day = day;
tasks[count].year = year;
count++;
}
int main()
{
int choice;
Tasks tasks[ARRAY_SIZE];
int count = 0;
bool quit = false;
readData(tasks, count);
while(!quit)
{
printMenu();
choice = getChoice(1, 5);
switch(choice)
{
case 1: printall(tasks, count);
break;
case 2: printtasksindaterange(tasks, count);
break;
case 3: completeatask(tasks, count);
break;
case 4: addtask(tasks, count);
break;
case 5: quit = true;
break;
}
}
return 0;
}
Tasks.txt
cs162 project 2 Need to do the add task part. 7 5 2018 0 clean bathroom Scrub the tub down 12 28 2017 1 cs162 read textbook Needs to be done before final. 8 1 2018 0
Dear student,
paste the code as per instructions below. do not forget to hit like button or thumbs up or upvote button.
//paste this in songs.cpp
#include "songs.h"
void Tasks::printUpdateMenu()
{
std::cout << "\n";
std::cout << "********** Main Manu**********" << std::endl;
std::cout << "1 - PRINT ALL TASKS: " << std::endl;
std::cout << "2 - PRINT TASKS IN DATE RANGE: " << std::endl;
std::cout << "3 - COMPLETE A TASK: " << std::endl;
std::cout << "4 - ADD TASK: " << std::endl;
std::cout << "5 - QUIT: " << std::endl;
}
void Tasks::printMenu()
{
std::cout << "\n";
std::cout << "********** Main Manu**********" <<std::endl;
std::cout << "1 - PRINT ALL TASKS: " << std::endl;
std::cout << "2 - PRINT TASKS IN DATE RANGE: " << std::endl;
std::cout << "3 - COMPLETE A TASK: " << std::endl;
std::cout << "4 - ADD TASK: " << std::endl;
std::cout << "5 - QUIT: " << std::endl;
}
int Tasks::getChoice(int a, int b)
{
int ch;
std::cout << "Enter choice: ";
std::cin >> ch;
std::cin.ignore(STR_SIZE, '\n');
std::cout << std::endl;
while((ch < a)||(ch > b))
{
std::cout << "not a valid choice. please re-enter" << std::endl;
std::cin >> ch;
std::cin.ignore();
}
return ch;
}
int Tasks::readData(Tasks tasks[], int &count)
{
std::ifstream infile("tasks.txt");
char ch = infile.peek();
while (!infile.eof() && ch != '\n')
{
std::cout << std::endl;
infile.getline(tasks[count].name, STR_SIZE);
infile.getline(tasks[count].desc, STR_SIZE);
infile >> tasks[count].month;
infile >> tasks[count].day;
infile >> tasks[count].year;
infile >> tasks[count].number;
infile.ignore(STR_SIZE, '\n');
count++;
}
infile.close();
return count;
}
void Tasks::printall(Tasks tasks[], int count)
{
for (int i = 0; i < count ; i++)
{
std::cout << "name: " << tasks[i].name << std::endl;
std::cout << "desc: " << tasks[i].desc << std::endl;
std::cout << "due: " << tasks[i].month << "/" << tasks[i].day
<< "/" << tasks[i].year << std::endl;
if (tasks[i].number == 0)
{
std::cout << "The task is not complited" << std::endl;
}
else if (tasks[i].number == 1)
{
std::cout << "The task is complited" << std::endl;
}
}
}
void Tasks::printtasksindaterange(Tasks tasks[], int count)
{
int year, month, day, year1, month1, day1;
std::cout << "Begin Date: "<< std::endl;
std::cout << "Enter year (2017 - 2067): ";
std::cin>> year;
if (year < 2017 || year > 2067)
{
std::cout << "Invalid year. Please Re-enter: ";
std::cin >> year;
}
std::cout << "Enter month (1 - 12): ";
std::cin>> month;
if (month <= 0 || month > 12)
{
std::cout << "Invalid month. Please Re-enter: ";
std::cin >> month;
}
std::cout << "Enter date (1 - 31): ";
std::cin>> day;
if (day <= 0 || day > 31)
{
std::cout << "Invalid day. Please Re-enter: ";
std::cin >> day;
}
std::cout << "Enter due year (2017 - 2067): ";
std::cin>> year1;
if (year1 < 2017 || year1 > 2067)
{
std::cout << "Invalid year. Please Re-enter: ";
std::cin >> year1;
}
std::cout << "Enter due month (1 - 12): ";
std::cin>> month1;
if (month1 <= 0 || month1 > 12)
{
std::cout << "Invalid month. Please Re-enter: ";
std::cin >> month1;
}
std::cout << "Enter due date (1 - 31): ";
std::cin>> day1;
if (day1 <= 0 || day1 > 31)
{
std::cout << "Invalid day. Please Re-enter: ";
std::cin >> day1;
}
int date1 = year*10000 + month*100 + day;
int date2 = year1*10000 + month1*100 + day1;
for (int i = 0; i < count; i++)
{
int k = tasks[i].year*10000 + tasks[i].month*100 + tasks[i].day;
if(k <= date2 && k >= date1 )
{
std::cout << "name: " << tasks[i].name << std::endl;
std::cout << "desc: " << tasks[i].desc << std::endl;
std::cout << "due: " << tasks[i].month << "/" << tasks[i].day
<< "/" << tasks[i].year << std::endl;
std::cout << "number: " << tasks[i].number << std::endl;
}
}
}
void Tasks::completeatask(Tasks tasks[], int count)
{
bool found = false;
char name[STR_SIZE];
std::cout << "Enter Name: "<< std::endl;
std::cin.getline(name, STR_SIZE, '\n');
for (int i = 0; i < count; i++)
{
std::cout<< "*" << tasks[i].name << "******"<<std::endl;
std::cout<< "*" << name<< "*" <<std::endl;
if(strcmp(tasks[i].name, name) == 0)
{
tasks[i].number = 1;
std::cout << "the task cs162 project 2 has been completed." << std::endl;
found = true;
}
}
if(!found)
{
std::cout<< " Invalid name"<< std::endl;
}
}
void Tasks::addtask(Tasks tasks[], int &count)
{
if(count >= ARRAY_SIZE)
{
std::cout << "no more room in inventory" << std::endl;
return;
}
char name[STR_SIZE], desc[STR_SIZE];
int year, month, day, number;
std::cout << "Enter Name: "<< std::endl;
std::cin.getline(name, STR_SIZE, '\n');
std::cout << "Enter Description (All On One Line): " << std::endl;
std::cin.getline(desc, STR_SIZE, '\n');
std::cout << "Entering Due Date: " << std::endl;
std::cout << "Enter month (1 - 12): ";
std::cin >> month;
if (month <= 0 || month > 12)
{
std::cout << "Invalid month. Please Re-enter: ";
std::cin >> month;
}
std::cout << "Enter day (1 - 31): ";
std::cin >> day;
if (day <= 0 || day > 31)
{
std::cout << "Invalid day. Please Re-enter: ";
std::cin >> day;
}
std::cout << "Enter year (2017 - 2067): ";
std::cin >> year;
if (year < 2017 || year > 2067)
{
std::cout << "Invalid year. Please Re-enter: ";
std::cin >> year;
}
std::cout << "Enter a number: " << std::endl;
std::cin >> number;
strcpy(tasks[count].name,name);
strcpy(tasks[count].desc,desc);
tasks[count].month = month;
tasks[count].day = day;
tasks[count].year = year;
count++;
}
// paste this in songs.h
#ifndef SONGS_H
#define SONGS_H
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>
const int ARRAY_SIZE = 100;
const int STR_SIZE = 250;
class Tasks
{
public:
int day, year, month, number;
char name[STR_SIZE + 1], desc[STR_SIZE + 1];
void printUpdateMenu();
void printMenu();
int getChoice(int a, int b);
int readData(Tasks tasks[], int &count);
void printall(Tasks tasks[], int count);
void printtasksindaterange(Tasks tasks[], int count);
void completeatask(Tasks tasks[], int count);
void addtask(Tasks tasks[], int &count);
};
#endif
// paste this in main program
#include <iostream>
using namespace std;
#include "songs.h"
int main()
{
int choice;
Tasks tasks[ARRAY_SIZE];
Tasks task;
int count = 0;
bool quit = false;
task.readData(tasks, count);
while(!quit)
{
task.printMenu();
choice = task.getChoice(1, 5);
switch(choice)
{
case 1: task.printall(tasks, count);
break;
case 2: task.printtasksindaterange(tasks, count);
break;
case 3: task.completeatask(tasks, count);
break;
case 4: task.addtask(tasks, count);
break;
case 5: quit = true;
break;
}
}
return 0;
}
-can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...
moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...
I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...
I have 2 issues with the C++ code below. The biggest concern is that the wrong file name input does not give out the "file cannot be opened!!" message that it is coded to do. What am I missing for this to happen correctly? The second is that the range outputs are right except the last one is bigger than the rest so it will not output 175-200, it outputs 175-199. What can be done about it? #include <iostream> #include...
#include "stdafx.h" #include <iostream> using namespace std; class dateType { private: int dmonth; int dday; int dyear; public: void setdate (int month, int day, int year); int getday()const; int getmonth()const; int getyear()const; int printdate()const; bool isleapyear(int year); dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) { int numofdays; if (year<=2008) { dyear=year;...
How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){ string seat, flight, book = "y"; int int_flight, p = 0, j = 0; int seat_number,...
I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...
How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...
Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found; string document[1000][6]; ifstream infile; char s[1000];...