Welcome! Log In Create A New Profile

Advanced

Assignment 1, Semester 2, Q4

Posted by mhld 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 1, Semester 2, Q4
July 30, 2009 04:53PM
Hi

i'm really struggling with Assignment 1, Semester 2, Question 4. i don't have a clue on how to tackle it. i need all the help i can get.


thanking you in advance
avatar Re: Assignment 1, Semester 2, Q4
July 31, 2009 08:19AM
Show some effort ... post code of how to at least open the file, etc ... smile
Re: Assignment 1, Semester 2, Q4
July 31, 2009 12:05PM
I can open the files, and copy text from the input file to the output file and to the screen. but am struggling with the printing the numbers, right-adjustment and the instructions that are give i.e Print the line number at the start of the line and right-adjusted in a field of three spaces. Follow the line number with a colon, then one space, then the text of the line.

my code so far is as below:


cout << "Enter input file name: ";
cin >> Input_file;

in_stream.open(Input_file);
if(in_stream.fail())
{
cout << "Input file failed to open.\n";
exit(1);
}

out_stream.open("output.txt"winking smiley;
if(out_stream.fail())
{
cout << "Output file failed to open.\n";
exit(1);
}

char next;

in_stream.get(next);
while (!in_stream.eof())
{
out_stream << next;
cout << next;
in_stream.get(next);
}
Re: Assignment 1, Semester 2, Q4
July 31, 2009 12:10PM
Comrade Coder...I think you should use setw function from <iomanip> library.smoking smiley
Copy...
Re: Assignment 1, Semester 2, Q4
July 31, 2009 12:42PM
cout.setf(ios::right)
Re: Assignment 1, Semester 2, Q4
July 31, 2009 04:01PM
i tried putting those functions. see below

char next;

in_stream.get(next);
while (!in_stream.eof())
{

out_stream << next;
cout << next;
out_stream.setf(ios::right);
out_stream << setw(3);
cout.setf(ios::right);
cout << setw(3);
in_stream.get(next);

}



and the below is the output that i get:

Enter input file name: MissMuffet.txt
L i t t l e M i s s M u f f e t
S a t o n a t u f f e t
E a t i n g h e r c u r d s a n d w
h e y
A l o n g c a m e a
s p i d e r
A n d c h a s e d h e r a w a yEND OF PROGRAM
Press any key to continue . . .

it puts a space between each character and how do i make it to output line numbers?
Sorry, only registered users may post in this forum.

Click here to login