Help on a program

Posts 1–4 of 4 · Page 1 of 1
Help on a program
So i'm creating a program,
#include <cstdlib>
#include <iostream>
using namespace std;


class File{
private:
****string name;
public:
****File(){
****}
****
****File(string name ){
********setName(name);
****}
****
****void print(){
*******cout<<getName();
****}
****void setName(string name){
********this->name =name;
****}
****string getName(){
********return this->name;
****}
};

class Directory{
private:
****string name;
****File files [100];
****
public:
****Directory(){
****}
****Directory(string name){
********setName(name);
****}
****
****void addf(File f, int i){
********files[i]=f;
****}
****
****void adddir(Directory d,int i){
********
****}
****void setName(string name){
********this->name =name;
****}
****string getName(){
********return this->name;
****}
****void print(){
********cout<<getName()<<endl;
********files[0].print();
************
****}
****
};
****

class FileSystem{
private:
*****Directory dir[100];
public:
****FileSystem(){
********
****}
****
****void add (Directory d, int i){
********dir[i]=d;
****}
****
****void print(){
********dir[0].print();
****}
};

int main(int av, char** argv) {
****
***FileSystem filesys;
***
***Directory d1("Documents");
***filesys.add(d1,0);
***File f1("HW1");
***d1.addf(f1,0);
***
***filesys.print();
***
****return 0;
}



I'm stuck to why the file isn't printing?

The output is “Documents”
Quote Originally Posted by Fliest_aladdin View Post
no one ?
damn
wanted to know what the three stars are used for
You declared the add function for the filesys too early before the f1 even exist to tell its name which means you only add the d1 that didn't contain file's name to the filesys. Supposed
Code:
int main(int av, char** argv) {

	FileSystem filesys;
	Directory d1("Documents");
	File f1("HW1");
	d1.addf(f1, 0);
	filesys.add(d1, 0);
	filesys.print();
	return 0;
}
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us