•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,655 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,790 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 949 | Replies: 5
![]() |
•
•
Join Date: Dec 2006
Location: Delaware
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hi everybody, this is my first post to the community and I need your help. I have a final project that I am working on for my C++ programming class. The functional particulars are:
- Program must be command-line based and interactive, allowing the user to control its operation by entering commands. For example, a user may type “add” and the program will respond by asking for data to add. Typing “exit” may end the program.
- Program must manage some type of record- or object-based data. In other words, it must manage multiple instances of the same type of data. So essentially, a collection of objects, each of which contains a collection of objects.
- Ability to accept new data entered by the user.
- Ability to search for specific, previously entered data.
- Ability to save all data to a file.
- Ability to retrieve previously stored data from the file.
- Ability to display a list of all data items and their sub-items.
- Maintainability Requirements:
- Program must have intelligible comments that adequately describe key parts of the code.
- All variables and class names should clearly describe their purpose and use consistent casing. Spelling doesn't’t count, but try your best.
- Program must comprise at least five classes.
- Program must use inheritance and demonstrate polymorphism.
- Program must use at least one loop.
- Program must read and write a file.
Deliverables
- Working object-oriented program meeting the above requirements. You must submit all the source code as well as a compiled executable.
- Simple user’s Guide that explains how your program works.
•
•
Join Date: Dec 2006
Location: Delaware
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Okay, I am posting what I have so far. Here goes.
#include<iostream>
#include<string>
#include"dvdType.h"
usingnamespace std;
ostream& operator<< (ostream& osObject, const dvdType& name)
{
osObject << name.dvdNameList << year.dvdYearList;
return osObject;
}
istream& operator>> (istream& isObject, dvdType& name)
{
isObject >> name.dvdNameList >> year.dvdYearList;
return isObject;
}
void dvdType::print() const
{
cout << dvdName << " " << dvdYear << endl;
}
void dvdType::setName(string name)
{
dvdName = name;
dvdYear = year;
}
string dvdType::getdvdNameList() const
{
return dvdName;
}
string dvdType::getdvdYearList() const
{
return year;
}
//constructor
dvdType::dvdType(string name, string year)
{
dvdName = name;
dvdYear = year;
}
//Program: Sales data analysis
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
usingnamespace std;
struct dvdLibrary
{
string dvdNameList; //name of dvd
string starNameList; //name of star of dvd
int dvdYearList; //year dvd released
string upcomingReleases; //projected releases to add to dvd collection
};
int main()
{
//Step 1
ifstream infile; //input file stream variable
ofstream outfile; //output file stream variable
string inputFile; //variable to hold the input file name
string outputFile; //variable to hold the output file name
cout << "Enter the Dvd name: "; //Step 2
cin >> inputFile; //Step 3
cout << endl;
infile.open(inputFile.c_str()); //Step 4
if (!infile) //Step 5
{
cout << "Cannot open the input file."
<< endl;
return 1;
}
initialize(infile, dvdNameList); //Step 6
infile.close(); //Step 7
infile.clear(); //Step 7
cout << "Enter the stars name: "; //Step 8
cin >> inputFile; //Step 9
cout << endl;
infile.open(inputFile.c_str()); //Step 10
if (!infile) //Step 11
{
cout << "Cannot open the input file."
<< endl;
return 1;
}
outfile.open(outputFile.c_str()); //Step 14
outfile << fixed << showpoint
<< setprecision(2); //Step 15
dvdNameList(infile, dvdNameList); //Step 16
starName(starNameList); //Step 17
dvdYear(dvdYearList);
starName(outfile, starNameList); //Step 20
dvdYear(outfile, dvdYearList); //Step 21
infile.close(); //Step 22
outfile.close(); //Step 22
return 0;
}
#ifndef H_dvdType
#define H_dvdType
#include<string>
usingnamespace std;
class dvdType
{
friend ostream& operator<< (ostream&, const dvdType &);
friend istream& operator>> (istream&, dvdType &);
public:
void print() const;
//Function to output the first name and last name
//in the form firstName lastName.
void setName(string);
//Function to set dvdName according
//to the parameters.
//Postcondition: dvdName = name.
string getDvdNameList() const;
//Function to return the name list.
//Postcondition: The value of the nameList is returned.
string getDvdYearList() const;
//Function to return the year of the dvd.
//Postcondition: The value of the dvdYear is returned.
dvdType(string name = "", string year = "");
//constructor
//Sets Name and year according to the parameters.
//The default values of the parameters are empty strings.
//Postcondition: nameList = name; yearList = year
private:
string nameList; //variable to store the first name
string yearList; //variable to store the last name
};
#endif
#include<iostream>
#include<string>
#include"dvdType.h"
usingnamespace std;
ostream& operator<< (ostream& osObject, const dvdType& name)
{
osObject << name.dvdNameList << year.dvdYearList;
return osObject;
}
istream& operator>> (istream& isObject, dvdType& name)
{
isObject >> name.dvdNameList >> year.dvdYearList;
return isObject;
}
void dvdType::print() const
{
cout << dvdName << " " << dvdYear << endl;
}
void dvdType::setName(string name)
{
dvdName = name;
dvdYear = year;
}
string dvdType::getdvdNameList() const
{
return dvdName;
}
string dvdType::getdvdYearList() const
{
return year;
}
//constructor
dvdType::dvdType(string name, string year)
{
dvdName = name;
dvdYear = year;
}
//Program: Sales data analysis
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
usingnamespace std;
struct dvdLibrary
{
string dvdNameList; //name of dvd
string starNameList; //name of star of dvd
int dvdYearList; //year dvd released
string upcomingReleases; //projected releases to add to dvd collection
};
int main()
{
//Step 1
ifstream infile; //input file stream variable
ofstream outfile; //output file stream variable
string inputFile; //variable to hold the input file name
string outputFile; //variable to hold the output file name
cout << "Enter the Dvd name: "; //Step 2
cin >> inputFile; //Step 3
cout << endl;
infile.open(inputFile.c_str()); //Step 4
if (!infile) //Step 5
{
cout << "Cannot open the input file."
<< endl;
return 1;
}
initialize(infile, dvdNameList); //Step 6
infile.close(); //Step 7
infile.clear(); //Step 7
cout << "Enter the stars name: "; //Step 8
cin >> inputFile; //Step 9
cout << endl;
infile.open(inputFile.c_str()); //Step 10
if (!infile) //Step 11
{
cout << "Cannot open the input file."
<< endl;
return 1;
}
outfile.open(outputFile.c_str()); //Step 14
outfile << fixed << showpoint
<< setprecision(2); //Step 15
dvdNameList(infile, dvdNameList); //Step 16
starName(starNameList); //Step 17
dvdYear(dvdYearList);
starName(outfile, starNameList); //Step 20
dvdYear(outfile, dvdYearList); //Step 21
infile.close(); //Step 22
outfile.close(); //Step 22
return 0;
}
#ifndef H_dvdType
#define H_dvdType
#include<string>
usingnamespace std;
class dvdType
{
friend ostream& operator<< (ostream&, const dvdType &);
friend istream& operator>> (istream&, dvdType &);
public:
void print() const;
//Function to output the first name and last name
//in the form firstName lastName.
void setName(string);
//Function to set dvdName according
//to the parameters.
//Postcondition: dvdName = name.
string getDvdNameList() const;
//Function to return the name list.
//Postcondition: The value of the nameList is returned.
string getDvdYearList() const;
//Function to return the year of the dvd.
//Postcondition: The value of the dvdYear is returned.
dvdType(string name = "", string year = "");
//constructor
//Sets Name and year according to the parameters.
//The default values of the parameters are empty strings.
//Postcondition: nameList = name; yearList = year
private:
string nameList; //variable to store the first name
string yearList; //variable to store the last name
};
#endif
•
•
•
•
i don't know how the smiley face got in there, please ignore it, it's not part of the code of course.
So what happens when you try to run it? Or compile it? Otherwise we just end up guessing.
A tip for writing your program: It looks like you're trying to write too many things at once. For example, I prefer to implement file I/O near the end of development of a program, and instead use constants. Why? Because I know constants work. It's one less thing to worry about when coding the body of the class.
tuxation.com - Linux articles, tutorials, and discussions
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
- Entertainment Site for sale over 60,000 pages of quality content (Websites for Sale)
- Favourite Movies? (Geeks' Lounge)
- Movie Database (C++)
- Retrieving Multiple Columns into Dropdown List (ASP.NET)
- Pascal database check (Pascal and Delphi)
Other Threads in the C++ Forum
- Previous Thread: PLEASE tell me is there a library like ncurses in C++
- Next Thread: Failing an input



Linear Mode