working with arrays, creating a video library

T

triplejump24

i LOVE doing c++ programming, but i never can get myself started! Once i
figure it out, its fun but anyways here it goes...
Im given a file c:\temp\hwk8input.txt, which contains the records of the
video collection of a small local library.
There are four fields for each video:
1) A unique video ID number without space (v1, v2, etc.);
2) The full video title;
3) The availability of the video (0 for checked out and 1 for checked
in);
4) A unique borrower ID without space (c0001, c0009, etc.) if the video is
checked out, otherwise blank.
Write code to read these data into your program, the display the following
menu to the user:
What do you want to do?
1. List all the videos
2. Check out a video
3. Exit the system

If you choose option one, videos displayed like this
Video ID: v1
Title: Godfather, The (1972)
Status: Checked out by c0001
......
And return to the menu.
If the user chooses option 2, ask for the video ID first
1) If the video ID is not valid, tell the user so and return to the menu.

2) If the video is checked in, ask for the borrower ID, then update the
status to be checked out and the borrower ID with the user input. Return
to the menu after processing.
3) If the video is already checked out, tell the user so and return to the
menu.
When the user chooses option 3, save the data back to the original input
file in the same format and terminate the program.
Your program should repeat the above until the user chooses to exit.





the following starting coade was already given to me


#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int readData(string id[], string title[], string available[], string
who[]);

void saveData(const string id[], const string title[], const string
available[], const string who[], int count);

void displayAll(const string id[], const string title[], const string
available[], const string who[], int count);

int search(const string arr[], string what, int count);

void checkout(const string id[], const string title[], string available[],
string who[], int count);

int showMenu();

int main() {
string vID[50], vTitle[50], checkedIn[50], bID[50];

//read data from the input files and get the number of videos returned
int nbrVideos = readData(vID, vTitle, checkedIn, bID);

int choice;
do{
choice = showMenu();
if(choice == 1)
displayAll(vID, vTitle, checkedIn, bID, nbrVideos);
else if(choice == 2)
checkout(vID, vTitle, checkedIn, bID, nbrVideos);
}while(choice != 3);

saveData(vID, vTitle, checkedIn, bID, nbrVideos);

return 0;




sorry this is so long, but hopefully anyone can help, id appreciate it.
Thanks in advance! :)
 
B

BobR

triplejump24 wrote in message ...
the following starting coade was already given to me
sorry this is so long, but hopefully anyone can help, id appreciate it.
Thanks in advance! :)

Glad to help....
int main(){
string vID[50], vTitle[50], checkedIn[50], bID[50];
//read data from the input files and get the number of videos returned
int nbrVideos = readData(vID, vTitle, checkedIn, bID);
int choice;
do{
choice = showMenu();
if(choice == 1)
displayAll(vID, vTitle, checkedIn, bID, nbrVideos);
else if(choice == 2)
checkout(vID, vTitle, checkedIn, bID, nbrVideos);
} while(choice != 3);
saveData(vID, vTitle, checkedIn, bID, nbrVideos);
return 0;

// Here is your first big problem. 'main()' needs a closing brace.
} // main() end


Now you will probably want to do the next step and write the body
(definition) for this:

int readData(string id[], string title[], string available[], string
who[]);
 
S

Salt_Peter

triplejump24 said:
i LOVE doing c++ programming, but i never can get myself started! Once i
figure it out, its fun but anyways here it goes...
Im given a file c:\temp\hwk8input.txt, which contains the records of the
video collection of a small local library.
There are four fields for each video:
1) A unique video ID number without space (v1, v2, etc.);
2) The full video title;
3) The availability of the video (0 for checked out and 1 for checked
in);
4) A unique borrower ID without space (c0001, c0009, etc.) if the video is
checked out, otherwise blank.

So write a class that represents a "video" record. That way each video
is a given type and you won't have to keep one container of IDs,
another container of titles, etc.

Your collection is a container of videos. Very simple.
Write code to read these data into your program, the display the following
menu to the user:
What do you want to do?
1. List all the videos
2. Check out a video
3. Exit the system

Thats useless, get the video storage system to work first.
If you choose option one, videos displayed like this
Video ID: v1
Title: Godfather, The (1972)
Status: Checked out by c0001
.....
And return to the menu.
If the user chooses option 2, ask for the video ID first
1) If the video ID is not valid, tell the user so and return to the menu.

2) If the video is checked in, ask for the borrower ID, then update the
status to be checked out and the borrower ID with the user input. Return
to the menu after processing.
3) If the video is already checked out, tell the user so and return to the
menu.
When the user chooses option 3, save the data back to the original input
file in the same format and terminate the program.
Your program should repeat the above until the user chooses to exit.





the following starting coade was already given to me

Well, sorry to hear that. What follows is exactly how *not* to do it.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int readData(string id[], string title[], string available[], string
who[]);

void saveData(const string id[], const string title[], const string
available[], const string who[], int count);

void displayAll(const string id[], const string title[], const string
available[], const string who[], int count);

int search(const string arr[], string what, int count);

void checkout(const string id[], const string title[], string available[],
string who[], int count);

int showMenu();

int main() {
string vID[50], vTitle[50], checkedIn[50], bID[50];

//read data from the input files and get the number of videos returned
int nbrVideos = readData(vID, vTitle, checkedIn, bID);

int choice;
do{
choice = showMenu();
if(choice == 1)
displayAll(vID, vTitle, checkedIn, bID, nbrVideos);
else if(choice == 2)
checkout(vID, vTitle, checkedIn, bID, nbrVideos);
}while(choice != 3);

saveData(vID, vTitle, checkedIn, bID, nbrVideos);

return 0;

sorry this is so long, but hopefully anyone can help, id appreciate it.
Thanks in advance! :)

Look at it this way, if i needed to store 10 people's names in a
container with their first name, last name, sex and age, i'ld do as
shown below. Why? Because the exact same code works whether i make 10
or one billion people. And frankly, if i can't store people, i couldn't
care less about some menu.

#include <iostream>
#include <string>
#include <vector>
#include <iterator>

class Person
{
int age;
bool sex;
std::string firstname;
std::string lastname;
public:
Person();
Person(int, bool,
const std::string&, const std::string&);
friend std::eek:stream&
operator<<(std::eek:stream&, const Person&);
};

Person::person()
: age(0), sex(true),
firstname(""), lastname("")
{
}

Person::person(int n, bool x, const std::string& fn,
const std::string& ln)
: age(n), sex(x),
firstname(fn), lastname(ln)
{
}

std::eek:stream&
operator<<(std::eek:stream& os, const Person& r_p)
{
std::cout << "name: " << r_p.firstname;
std::cout << " " << r_p.lastname;
std::cout << "\tsex = " << std::boolalpha << r_p.sex;
std::cout << "\tage = " << r_p.age;
return os << std::endl;
}

int main()
{
Person person(25, true, "Mary", "Smith");
std::vector< Person > people(10, person); // 10 people

std::copy( people.begin(),
people.end(),
std::eek:stream_iterator< Person >(std::cout));
}

/*
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
name: Mary Smith sex = true age = 25
*/
 
H

Howard

triplejump24 said:
i LOVE doing c++ programming, but i never can get myself started! Once i
figure it out, its fun but anyways here it goes...
Im given a file c:\temp\hwk8input.txt, which contains the records of the
video collection of a small local library. ....
the following starting coade was already given to me

This is obviously your homework. It's up to you to do your own work. If
you need help with something specific, post the code you're having a problem
with and tell us what help you need with that code (such as "Why does this
line gives me such-and-such an error?"), and we'll be glad to help. We're
not going to simply do your homework for you, though.

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top