lotrsimp12345 37 Posting Pro in Training

but it supposed to change. I am still confused.

lotrsimp12345 37 Posting Pro in Training

Basically the please hit any key to enter doesn't show up in Visual C++.Thanks for help

main

//CS 310
/*Create a text file and input in certain data into the text
file*/
//Program one

#include <iostream>
#include <fstream>
#include "Account.h"
using namespace std;
int main()
{
    account b;
    char name1[256];
    cout<<"enter file name to be opened\n";
    cin>>name1;
    ofstream infile;
    infile.open(name1);
    if(!infile)
    {
        cout<<"File could not open\n";
        exit(1);
    }
    else
    {   
        while(b.get_account_number()!=-1)
        {
            if(b.get_account_number()==-1)
            {
                cout<<"account number is one\n";
                infile.close();
                //exit(1);
            }
            else
            {
            cout<<"enter while loop\n";
            cin>>b;
            infile<<b;
            }

        }
    }

    return 0;
}

Interface

//class used to create an account

#include <string>
using namespace std;
class account
{
private: 
    int account_Number;
    string name;
    string address;
    string city;
    string state;
    int zip_Code;
    double account_Balance;
public:

    //default account constructor
    account(int=0,  string="", string="", string="", string="", int=0, double=0);

    //sets the private variables above
    void set_account_number(size_t account_Number_Value);
    void set_title(string first_Last);
    void set_address(string location);
    void set_city(string county);
    void set_state(string loc);
    void set_zip_code(int zip);
    void set_account_balance(double user_balance);

    //gets the members value
    int get_account_number();
    string get_title();
    string get_address();
    string get_city();
    string get_state();
    int get_zip_code();
    double get_account_balance();

};

//overloaded operator to allow an object to be read in
istream& operator>>(istream&in,account& c);

//overload operator to an object to be read to the file
ostream& operator<<(ostream& out, account& z);

IMPLEMENTATION

#include "Account.h"
#include <iostream>
#include <iomanip>
using namespace std;

account::account(int accountNumberValue,string nameValue,string addressValue, string cityValue, string stateValue,
                 int zipCodeValue,double AccountBalanceValue)
{
    set_account_number(accountNumberValue);
    set_title(nameValue);
    set_address(addressValue);
    set_city(cityValue);
    set_state(stateValue);
    set_zip_code(zipCodeValue);
    set_account_balance(AccountBalanceValue);
}

void account::set_account_number(size_t account_Number_Value)
{
    account_Number=account_Number_Value;
} …
lotrsimp12345 37 Posting Pro in Training

thanks for trying.

lotrsimp12345 37 Posting Pro in Training

here's what i put down: The file manager must first read a sector to make sure that it has enough empty space in the sector to write the record to disk. To decrease the number of times such a read is likely to occur we can calculate how much space is in a sector the first time a read is called and only call read again after that sector can hold no more information. Continue subtracting from that first read until a record being inserted is too big to fit into a sector.

lotrsimp12345 37 Posting Pro in Training

In early linux systems, inodes were kept together on one part of a disk, while the corresponding data was scattered elsewhere on the disk. Later editions divided disks drives into group of adjacent cylinders called cylinder groups, in which each cylinder group contains inodes and their corresponding data. How does this new organization improve performance?

lotrsimp12345 37 Posting Pro in Training

My understand is in generic programming you can have multiple containers, which use iterators but use the same algorithm. Wouldn't template be considered a ADT? Really confused.

lotrsimp12345 37 Posting Pro in Training

I would say yes since both are ways of storing information.

lotrsimp12345 37 Posting Pro in Training

thanks for all the help. Figured it out :)

lotrsimp12345 37 Posting Pro in Training

SO CLOSE BUT LAST NODE STORES memory address

void my_int_sllist::pop_back()
{	
	cout<<"enter pop_back";
	if(head==tail)
	{
		//cout<<"enter head==tail?";
		delete head;
		head=tail=0;
		siz--;
	}
	else
	{
		//cout<<"enter's other condition";
		my_int_node* temp=head;
		for(temp=head; temp->next!=0; temp=temp->next)
		{
			cout<<"number";
			tail=temp;
		}
		delete tail;
		tail->next=0;
		
		siz--;
	}
}
lotrsimp12345 37 Posting Pro in Training

thanks that helped a lot. Almost got it figured out just don't know why the last element in list would be a memory location.

lotrsimp12345 37 Posting Pro in Training

sweet kind of got it to work but the problem is returns memory location.

lotrsimp12345 37 Posting Pro in Training
for(temp=head; temp->next==tail; temp=temp->next)
{
tail=temp;

}
tail->next=0;

any hints as to how to fix this?

lotrsimp12345 37 Posting Pro in Training

STILL UNSOLVED
NODE CLASS

//class used to create a node

class my_int_node
{
public:
	//member that stores the nodes data value
	int data;
	
	//pointer to next list node
	my_int_node* next;

	/*constructor that creates a node when invoked
	by specifiying what value and a pointer to the 
	next node */
	inline my_int_node(int value, my_int_node* follow=0)
	{
		data=value;
		next=follow;
	}
};

LIST.h

#include "My_Int_Node.h"

class my_int_sllist
{
public:
	//constructor to create an empty list
	my_int_sllist();

	/*Insert a node containing number at the first position 
	of the singly linked list*/
	void push_front(int number);

	/*Insert a new node containing number at the last position 
	of the singly linked list*/
	void push_back(int number);

	// Delete the first node of the singly linked list
	void pop_front();

	// Delete the first node of the singly linked list
	void pop_back();

	//number of nodes that store values
	int size();

	//prints out the list
	void show_int_sllist();

private:
	//pointers to front and back of list
	my_int_node* head, *tail;

	//tell number of nodes that are filled in the list
	int siz;
};

List.cpp

#include "My_Int_Sllist.h"
#include <iostream>
using namespace std;

my_int_sllist::my_int_sllist()
{
	head=0;
	tail=0;
	siz=0;
}

void my_int_sllist::push_front(int number)
{
	/*1.Creates an empty node
	2.nodes data member initalized to a particular value
	3.adding to front, so to connect current node to rest must update
	the next member to head position
	4.must update value of head to make it point to current node*/
	head=new my_int_node(number,head);
	//if their is an empty list
	if(tail==0)
	{
		tail=head;
	}
	siz++;
}

void my_int_sllist::push_back(int …
lotrsimp12345 37 Posting Pro in Training

thanks a lot.

lotrsimp12345 37 Posting Pro in Training
void my_int_sllist::pop_back()
{
//head and tail pointers 
	cout<<"enter pop_back";
//contains one node
	if(head==tail)
	{
		cout<<"enter head==tail?";
		delete head;
		head=tail=0;
		siz--;
	}
	else
	{
		cout<<"enter's other condition";
		my_int_node* temp;
		for(temp=head; temp->next!=tail; temp=temp->next)
		{
			delete tail;
			tail=temp;
			tail->next=0;
		}
		siz--;
	}
}
lotrsimp12345 37 Posting Pro in Training

Why doesn't pop_back method work? or is their something wrong with show_int_sllist()? Has to be pop_back because when i get rid of show_int_sllist error still shows up. PLEASE HELP.

#include "My_Int_Sllist.h"
#include <iostream>
using namespace std;

my_int_sllist::my_int_sllist()
{
	head=0;
	tail=0;
	siz=0;
}

void my_int_sllist::push_front(int number)
{
	/*1.Creates an empty node
	2.nodes data member initalized to a particular value
	3.adding to front, so to connect current node to rest must update
	the next member to head position
	4.must update value of head to make it point to current node*/
	head=new my_int_node(number,head);
	//if their is an empty list
	if(tail==0)
	{
		tail=head;
	}
	siz++;
}

void my_int_sllist::push_back(int number)
{
	//the list isn't empty
	if(tail!=0)
	{
		/*1.create an empty node
		2.the new nodes member is initalized to number
		3.next is set to null since it is at end of list 
		and doesn't need to create a new link to the next node
		4.tail->next is the next member of the node pointed to by tail 
		thus making the next member point to the new node*/
		tail->next=new my_int_node(number);

		//must update value of tail so that the last value may be accessed
		tail=tail->next;
	}
	//list is empty
	else
	{
		/*1.create a empty node
		2.new nodes member is initalized to number
		3.need to update tail and head pointer so that 
		they point to the node allowing access*/
		head=tail=new my_int_node(number);
	}
	siz++;
}

void my_int_sllist::pop_front()
{
	//int el=head->data;
	//temp is a pointer that gets node pointed to by head
	my_int_node* temp=head;

	//empty list
	if(head==0&&tail==0)
	{
		cout<<"can't remove from …
lotrsimp12345 37 Posting Pro in Training

nvm figured it out.
Thanks.

lotrsimp12345 37 Posting Pro in Training

sort of seems to be working, but won't print last value :(

void my_int_sllist::show_int_sllist()
{
	my_int_node* temp=head;
	while(temp->next!=0)
	{
		cout<<temp->data<<"\n";
		temp=temp->next;
	}
	/*for(temp=head; temp->next!=tail; temp=temp->next)
	{
		cout<<temp->data<<"\n";
	}*/
}
lotrsimp12345 37 Posting Pro in Training

the problem seems to be in the show_int_sllist().

main

#include "My_Int_Sllist.h"
#include <iostream>

using namespace std;

int main()
{
	//Test1
	my_int_sllist b;
	b.push_back(10);
	b.show_int_sllist();
	return 0;
}

INTERFACE NODE

//class used to create a node

class my_int_node
{
public:
	//member that stores the nodes data value
	int data;
	
	//pointer to next list node
	my_int_node* next;

	/*constructor that creates a node when invoked
	by specifiying what value and a pointer to the 
	next node */
	inline my_int_node(int value, my_int_node* follow=0)
	{
		data=value;
		next=follow;
	}
};

INTERFACE LIST

#include "My_Int_Node.h"

class my_int_sllist
{
public:
	//constructor to create an empty list
	my_int_sllist();

	/*constrcutor to create a list of a certain size
	and intialize it to a value*/
	my_int_sllist(size_t intial_size, size_t value);

	/*Insert a node containing number at the first position 
	of the singly linked list*/
	void push_front(int number);

	/*Insert a new node containing number at the last position 
	of the singly linked list*/
	void push_back(int number);

	// Delete the first node of the singly linked list
	void pop_front();

	// Delete the first node of the singly linked list
	void pop_back();

	//number of nodes that store values
	int size();

	//prints out the list
	void show_int_sllist();

private:
	//pointers to front and back of list
	my_int_node* head, *tail;

};

IMPLEMENTATION

#include "My_Int_Sllist.h"
#include <iostream>
using namespace std;

my_int_sllist::my_int_sllist()
{
	head=0;
	tail=0;
}

void my_int_sllist::push_front(int number)
{
	/*1.Creates an empty node
	2.nodes data member initalized to a particular value
	3.adding to front, so to connect current node to rest must update
	the …
lotrsimp12345 37 Posting Pro in Training

so why do i have to assign the size member since i already have b.siz ?

lotrsimp12345 37 Posting Pro in Training

Here's the function:

my_int_vector::my_int_vector(const my_int_vector& b)
{
	numbers=new int[b.capacit];
	for(size_t j=0; j<b.siz; j++)
	{
		numbers[j]=b.numbers[j];
	}
}
lotrsimp12345 37 Posting Pro in Training

When i run a black screen with cursor appears but nothing prints
THANKS
INTERFACE

//my_int_vector.h 

class my_int_vector
{
public:
	//destructor
	~my_int_vector();

	//copy constructor
	my_int_vector(const my_int_vector& b);

	//constructor that create an empty vector
	my_int_vector();

	/*constructor that create an vector with capacity specified 
	as a parameter but doesn't assign values to each element
	in the vector*/
	my_int_vector(unsigned int intial_Size);

	/*constructor that create a vector with capacity specified 
	as a parameter and assign all the elements the value 
	specified*/
	my_int_vector(unsigned int intial_Size, int assign);
	
	


	//returns total number of elements in an array
	int capacity();
	
	//returns number of elements in array that are filled
	int size();

	//adds an value at next position in vector
	void push_back(size_t user_number);

	//prints out the vector that contains the numbers
	void show_int_vector();

	//deletes the number from last element that stores a number
	void pop_back();

	//return value at the index specified by user
	int at(size_t arrayindex);
	
	//return value at index specified by user
	int operator[](size_t array_index);

private:

	//array to store numbers
	int* numbers;

	//total amount of elements that can be stored in array
	size_t capacit;

	//number of elements that are filled
	size_t siz;
};

IMPLEMENTATION

//Implementation of functions in my_int_vector.h

#include <iostream>
#include "my_int_vector.h"
using namespace std;

my_int_vector::~my_int_vector()
{
	delete[] numbers;
}

my_int_vector::my_int_vector(const my_int_vector& b)
{
	numbers=new int[capacit];
	for(size_t j=0; j<siz; j++)
	{
		numbers[j]=b.numbers[j];
	}
}

my_int_vector::my_int_vector()
{
	//cout<<"intial vector\n";
	siz=0;
	capacit=0;
	numbers=NULL;
}

my_int_vector::my_int_vector(unsigned int intial_Size)
{
	//cout<<"intial vector\n";
	siz=0;
	capacit=intial_Size;
	numbers=new int[capacit];
}

my_int_vector::my_int_vector(unsigned int intial_Size,int assign)
{
	//cout<<"intial vector\n";
	siz=0;
	capacit=intial_Size;
	numbers=new int[capacit]; …
lotrsimp12345 37 Posting Pro in Training

thanks. Have no idea what he wanted. apparently you can link two programs together in ms-dos and achieve this. Atleast that's what i think he wanted us to do.

lotrsimp12345 37 Posting Pro in Training

First problem works now, the new problem is how to move the postion forward to find newline.

lotrsimp12345 37 Posting Pro in Training
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;

int main()
{

	int number_Of_Lines_To_Print_From_End=0;
	char file_name[20];
	int first_data,data_loc;
	cout<<"enter file name that needs to be opened\n";
	cin>>file_name;
	cout<<"enter number of lines to print from end of file\n";
	cin>>number_Of_Lines_To_Print_From_End;
	fstream file,indexfile;
	file.open(file_name, ios::in );
	indexfile.open("output.txt", ios::out);
	if(file.is_open())
	{
		cout<<"the file opened\n";
	}
	else
	{
		cout<<"the file didn't open\n";
	}
	if(indexfile.is_open())
	{
		cout<<"the file opened\n";
	}
	else
	{
		cout<<"the file didn't open\n";
	}
	
	first_data=file.tellg();
	data_loc=first_data;
	file.peek();
	while(!file.eof())
	{
		indexfile <<data_loc<<"\n";
		data_loc=file.tellg();
		file.peek();
	}
	indexfile.close();
	//clear eof flags
	file.clear();
	file.seekg(first_data);
	return 0;
}
lotrsimp12345 37 Posting Pro in Training
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;

int main()
{

    int number_Of_Lines_To_Print_From_End=0;
    char file_name[20];
    streampos length;
    cout<<"enter file name that needs to be opened\n";
    cin>>file_name;
    cout<<"enter number of lines to print from end of file\n";
    cin>>number_Of_Lines_To_Print_From_End;
    fstream file;
    file.open(file_name, ios::out );
    if(file.is_open())
    {
        cout<<"the file opened\n";
    }
    else
    {
        cout<<"the file didn't open\n";
    }

    file.seekg(0,ios::end);
    length=file.tellg();
    file.seekg(0,ios::beg);
    cout<<"the length is"<<length<<"\n";
    return 0;
}
lotrsimp12345 37 Posting Pro in Training

so i am assuming i am supposed to do what unix pipe commands do in C++?

lotrsimp12345 37 Posting Pro in Training

Basically my assignment says. Write a program to read a series of names, one per line, from standard input and write out those names spelled in reverse order to standard output. Use I/O redirection and pipes to do the following:

a) Input a series of names that are typed in from keyboard, and write them out, reversed to file1.
b)Read the names in from file1; then write them out,re-reversed, to a file called file2.
c) Read the names in from file2, reverse them again, and then sort the resulting list of reversed words using sort.

So doesn't this imply that i must have unix. Which i don't so how am i supposed to do this?

lotrsimp12345 37 Posting Pro in Training

that's what i thought. thanks for help. Sorry for all the questions teacher doesn't really explain anything about file structures and the book we are using is super old. .

lotrsimp12345 37 Posting Pro in Training

In unix if you create and open a file by using 9 digits numbers in the open function it seems to work but in C++ you only don't have a parameter to do that rather you have ios_base. Just wondering if there are owner,group and world settings that can be set on a file when it is created in C++?

lotrsimp12345 37 Posting Pro in Training

so use the same commands as in C?

lotrsimp12345 37 Posting Pro in Training

I know their are some in C so shouldn't their be some in C++?

lotrsimp12345 37 Posting Pro in Training

thanks.

lotrsimp12345 37 Posting Pro in Training

i am currently in a file structure class and my teach teaches me the basic of C++ the book talks about unix and C so it is super confusing. And the books questions are in C++. Anyone know any basic link on file structures?

lotrsimp12345 37 Posting Pro in Training

O_RWDR opens a file for read and write and pmode allows you to specify permission for each of the users?

WHAT DOES IT MEAN BY WHAT PMODES AND O_RDWR ARE AVALABLE ON YOUR SYSTEM? CONSIDERING I AM USING VISTA I HAVE NO IDEA.

I HAVE THE ABILITY TO READ AND WRITE TO A FILE. IS THAT WHAT IS EXPECTED?

lotrsimp12345 37 Posting Pro in Training

JUST WONDERING IF THIS IS BETTER CODE.
test

#include "my_int_vector.h"
#include <iostream>

using namespace std;
int main()
{
	my_int_vector b(0);
	b.push_back(10);
	//b.show_int_vector(b);
	b.push_back(122);
	b.show_int_vector(b);
	//b.push_back(20000);
	return 0;
}

Implementation

#include <iostream>
#include "my_int_vector.h"
using namespace std;

my_int_vector::my_int_vector(int intial)
{
	if(intial==0)
	{
		array_index=intial;
		numbers=NULL;
		//temp=NULL;
	}
	else if(intial>0)
	{
		array_index=intial;
		numbers=NULL;
		numbers=new int[array_index];
		//temp=NULL;
	}
}

int my_int_vector::at(size_t arrayindex)
{
	return numbers[arrayindex];
}

int my_int_vector::operator [](size_t array_index)
{
	return numbers[array_index];
}

void my_int_vector::push_back(size_t user_number)
{
	int* temp;
	if(array_index==0)
	{
		array_index=array_index+1;
		numbers=new int[array_index];
		numbers[0]=user_number;
		cout<<"from if"<<numbers[0]<<"\n";
	}
	else
	{
		array_index=array_index+1;
		temp=numbers;
		numbers=new int[array_index];
		for(size_t i=0; i<=array_index-2; i++)
		{
			numbers[i]=temp[i];
		}
		numbers[array_index-1]=user_number;

	}

	
}

/*void my_int_vector::pop_back()
{
	
	temp=new int[array_index];
	for(size_t c=0; c<array_index; c++)
	{
		temp[c]=numbers[c];
	}
	array_index=array_index-1;
	numbers=new int[array_index];
	for(size_t h=0; h<array_index; h++)
	{
		numbers[h]=temp[h];
	}
	delete [] temp;
	temp=NULL;
}*/

int my_int_vector::capacity()
{
	return array_index;
}

void my_int_vector::show_int_vector(my_int_vector& b)
{
	cout<<numbers[0]<<numbers[1]<<"\n";

}

Interface

class my_int_vector
{
public:
	//constructor to create an array
	my_int_vector(int intial);
	
	//prints out the vector that contains the numbers
	void show_int_vector(my_int_vector& b);

	//returns value at arrayindex
	int at(size_t arrayindex);
	
	//returns value at arrayindex
	int operator[](size_t array_index);

	//add value to end of array
	void push_back(size_t user_number);

	//delete value from end of array
	//void pop_back();

	//returns total number of elements that can be stored in the list
	int capacity();

	
private:

	//array to store numbers
	int* numbers;
	//
	size_t array_index;
};
lotrsimp12345 37 Posting Pro in Training

thanks for the help. I figured it out.

Salem commented: Excellent - that's the spirit! +17
lotrsimp12345 37 Posting Pro in Training

please tell me what is wrong with my push_back function?

lotrsimp12345 37 Posting Pro in Training

Maybe a bit more explanation would help. STILL CONFUSED ABOUT WHAT IS WRONG WITH FUNCTION.

lotrsimp12345 37 Posting Pro in Training

Please tell me what is wrong.

lotrsimp12345 37 Posting Pro in Training

show_int_vector method RETURNS MEMORY LOCATION FOR EVERTHING EXCEPT FOR LAST VALUE.


main

#include "my_int_vector.h"
#include <iostream>

using namespace std;
int main()
{
	my_int_vector b(0);
	b.push_back(10);
	//b.show_int_vector(b);
	b.push_back(122);
	b.show_int_vector(b);
	//b.push_back(20000);
	return 0;
}

Interface

class my_int_vector
{
public:
	//constructor to create an array
	my_int_vector(int intial);
	
	//prints out the vector that contains the numbers
	void show_int_vector(my_int_vector& b);

	//returns value at arrayindex
	int at(size_t arrayindex);
	
	//returns value at arrayindex
	int operator[](size_t array_index);

	//add value to end of array
	void push_back(size_t user_number);

	//delete value from end of array
	void pop_back();

	//returns total number of elements that can be stored in the list
	int capacity();

	
private:

	//array to store numbers
	int* numbers;
	//array of temp values
	int* temp;
	//array of values which need to be printed which would be the valid ones
	int* print;
	//
	size_t array_index;
};

Implementation

#include <iostream>
#include "my_int_vector.h"
using namespace std;

my_int_vector::my_int_vector(int intial)
{
	if(intial==0)
	{
		array_index=intial;
		numbers=NULL;
		temp=NULL;
	}
	else if(intial>0)
	{
		array_index=intial;
		numbers=NULL;
		numbers=new int[array_index];
		temp=NULL;
	}
}

int my_int_vector::at(size_t arrayindex)
{
	return numbers[arrayindex];
}

int my_int_vector::operator [](size_t array_index)
{
	return numbers[array_index];
}

void my_int_vector::push_back(size_t user_number)
{
	if(array_index==0)
	{
		array_index=array_index+1;
		numbers=new int[array_index];
		numbers[0]=user_number;
	}
	else
	{
		temp=new int[array_index];
		for(size_t a=0; a<array_index; a++)
		{
			temp[a]=numbers[a];
			
		}
		delete[] numbers;
		numbers=NULL;
		array_index=array_index+1;
		numbers=new int[array_index];
		for(size_t b=0; b<array_index-2; b++)
		{
			numbers[b]=temp[b];
		}
		delete [] temp;
		temp=NULL;
		numbers[array_index-1]=user_number;
	}
}

void my_int_vector::pop_back()
{
	
	temp=new int[array_index];
	for(size_t c=0; c<array_index; c++)
	{
		temp[c]=numbers[c];
	}
	array_index=array_index-1;
	numbers=new int[array_index];
	for(size_t h=0; h<array_index; h++)
	{
		numbers[h]=temp[h];
	}
	delete [] temp;
	temp=NULL;
} …
lotrsimp12345 37 Posting Pro in Training

Please help!!!!

lotrsimp12345 37 Posting Pro in Training

i did it doesn't work with the ifstream.

lotrsimp12345 37 Posting Pro in Training

so this would work for both the cin and infile?

lotrsimp12345 37 Posting Pro in Training

and how i would go about fixing it?
main

#include <iostream>
#include "Format.h"
#include <fstream>
using namespace std;

int main()
{
    Format format;
    //string word;
    char in;
    ifstream infile;
    bool a=true;
    bool b=true;
    bool c=true;
    while(b==true)
    {
        cout<<"to quit type 'q'\n"
            <<"enter 'c' to get from console\n"
            <<"enter 'f' to get from file\n";
        cin>>in;
        if(in=='q')
        {
            cout<<"quit program\n";
            a=false;
            b=false;
        }
        else if(in=='c')
        {
            cout<<"enter console\n";
            a=true;
            c=true;
        }
        else if(in=='f')
        {
            cout<<"read from file\n";
            a=true;
            c=false;
        }
        if(a==true&&c==false)
        {
          cout<<"from f\n";
                string input;
                cout<<"enter file name which needs to be opened\n";
                cin>>input;
                while(!infile)
                {
                    infile.open(input.c_str());
                    if(!infile.is_open())
                    {
                        infile.close();
                        cout<<"the input textfile failed please reenter the file\n";
                        infile.clear();
                    }
                }
                cout<<"the file opened\n";
                //cout<<format.read_data(infile);
                infile>>format;
                cout<<format;
                b=true;
        }
        else if(a==true&&c==true)
        {
            cin>>format;
            //cout<<format.read_data(cin);
            cout<<format;
            b=true;
        }
    }
    return 0;
}

the infile line doesn't work :(
Implementation

#include "Format.h"
#include <vector>
#include <iostream>
using namespace std;

Format::Format()
{
    width=0;
    height=0;
    border='*';
    justification='l';
}

void Format::setJustification(char x)
{
    //cout<<"the just is"<<x<<"\n";
    justification=x;
}
char Format::getJustification()
{
    return justification;
}
void Format::setborder(char b)
{
    border=b;
}

void Format::add_word(string w)
{
   
    if(width<w.length())
    {
        width=w.length();
    }
    height++;
    words.push_back(w);
}

string Format::get_word(int index)
{
    return words[index];
}
char Format::get_border()
{
    return border;
}

size_t Format::get_width()
{
    return width;
}
size_t Format::get_height()
{
    return height;
}

void Format::add_justif(char x)
{
    justif.push_back(x);
}

char Format::getjustif(size_t z)
{
    //cout<<"justif size"<<justif.size()<<"\n";
    return justif[z];
}

ostream& operator<< (ostream& out,Format a)
{
   
    for(size_t b=0; b<(a.get_width()+2); b++)
    {
        out<<a.get_border();
    }
    out<<"\n";
    for(size_t b=0; b<(a.get_height()); b++)
    {
        //out<<"justification"<<a.getJustification()<<"\n";
        out<<a.get_border(); …
lotrsimp12345 37 Posting Pro in Training

thanks for help.

lotrsimp12345 37 Posting Pro in Training

nvm it I think i know why the numbers were printing out, because i was asking for them to be printed out. with the out<<

lotrsimp12345 37 Posting Pro in Training

but why would it get numbers? when i am not asking it to? and can ios_base only be used with cout?

lotrsimp12345 37 Posting Pro in Training

Random numbers appear and i have no idea where they are appearing from. Problem is in << operator. Not sure how to fix it.

Main

#include <iostream>
#include "Format.h"

using namespace std;

int main()
{
    Format format;
    format.setJustification('l');
    format.add_word("one");
    format.add_word("two");
    format.add_word("is");
    cout<<format;
    return 0;
}

Implementation

#include "Format.h"
#include <vector>
#include <iostream>
using namespace std;

Format::Format()
{
    width=0;
    height=0;
    border='*';
    justification='l';
}

void Format::setJustification(char x)
{
    justification=x;
}
char Format::getJustification()
{
    return justification;
}
void Format::setborder(char b)
{
    border=b;
}

void Format::add_word(string w)
{
    if(width<w.length())
    {
        width=w.length();
    }
    height++;
    words.push_back(w);
}

string Format::get_word(int index)
{
    return words[index];
}
char Format::get_border()
{
    return border;
}

int Format::get_width()
{
    return width;
}
size_t Format::get_height()
{
    return height;
}

ostream& operator<< (ostream& out,Format a)
{
    //out<<a.get_width();
    //out<<a.get_height();
    for(size_t b=0; b<(a.get_width()+2); b++)
    {
        out<<a.get_border();
    }
    out<<"\n";
    for(size_t b=0; b<(a.get_height()); b++)
    {
        if(a.getJustification()=='l')
        {
        out<<a.get_border();
        out<<ios_base::left;
        out<<a.get_word(b);
        out<<out.width(a.get_width()-1);
        out<<a.get_border()<<"\n";
        }
    }
    for(size_t b=0; b<(a.get_width()+2); b++)
    {
        out<<a.get_border();
    }
    return out;
}

Interface

#ifndef FORMAT_H_INCLUDED
#define FORMAT_H_INCLUDED
using namespace std;
#include<vector>
class Format
{
    private:
    //max length of frame
    size_t width;
    //max height of frame
    int height;
    //boder character
    char border;
    //store words to be displayed
    vector<string> words;
    //store alignment
    char justification;
    public:
    Format();
    void setJustification(char x);
    void setborder(char b);
    void add_word(string w);
    int get_width();
    size_t get_height();
    char get_border();
    char getJustification();
    string get_word(int index);
    string is_line(int f);
    string print_char();
};
ostream& operator<< (ostream& out,Format a);



#endif // FORMAT_H_INCLUDED
lotrsimp12345 37 Posting Pro in Training

i will just put the open function in my main and then call it.
Thanks for trying.