need help with this

write a program that reads a line from a file called quote.txt containing the text, a.b.c.d.e,f and write the uppercase version of that line in reverse to the output file named upquote.txt.
closed account (48T7M4Gy)
So how far have you got with this?
am a beginner in programming and i was wondering how to get by this

A good plan is to break the problem down into smaller, easily manageable steps.

This tutorial should help with the file access:
http://www.cplusplus.com/doc/tutorial/files/

Then you are left with two additional steps.
a) convert to uppercase
b) reverse the string

You could use the function toupper() to convert a single character to uppercase
http://www.cplusplus.com/reference/cctype/toupper/
To convert an entire string, you need to iterate through each character in turn.

To reverse the string - there are many approaches, for example iterating backwards through the string from the last character to the first.

its the uppercase part am have issues with? can anyone please help
Please show the program code you have written so far, to show what issues there are with the code. Then specific help can be given as needed.
closed account (48T7M4Gy)
its the uppercase part am have issues with? can anyone please help


Good to see you have done all the rest. After all you started with nothing and now you've narrowed down to just the upper case part.

Just show us the rest and we'll give you a clue which one of you lines might be the place to put Chervils toupper() suggestion.
#include <iostream>
#include <string>
#include <fstream>

using namespace std;


int main(){

ifstream myInfile;
ofstream myOutfile;
string mystr;
int toupper(int mystr);
myInfile.open("quote.txt");
myOutfile.open("upquote.txt");

getline(myInfile, mystr);
cout << mystr << endl;


myInfile.close();
myOutfile.close();
system("pause");
return 0;
closed account (48T7M4Gy)
This is a start. Carefully examine the output on display and files. Hint: extend the idea with a loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
    int toupper(int mystr);
    
    ifstream myInfile;
    myInfile.open("quote.txt");
    
    string mystr;
    getline(myInfile, mystr);
    cout << mystr << endl;
    
    mystr[2] = toupper(mystr[2]); //<--
    cout << mystr << endl;
    
    ofstream myOutfile;
    myOutfile.open("upquote.txt");
    myOutfile << mystr; // <--
    
    myInfile.close();
    myOutfile.close();
    
    return 0;
}


quote.txt
a.b.c.d.e,f 


unquote.txt
a.B.c.d.e,f
Last edited on
Thank you very much for your assistant but i need the full line to be in uppercase not just B.

mystr = toupper(mystr); not correct
roscor16 wrote:
i need the full line to be in uppercase

As stated previously:
chervil wrote:
To convert an entire string, you need to iterate through each character in turn.


That is to say, you need to use a loop to go through the string one character at a time. The first character is mystr[0]. The length of the string is mystr.size(). Loop from 0 to length-1.
closed account (48T7M4Gy)
Thank you very much for your assistant but i need the full line to be in uppercase not just B.

You're welcome roscor16. Can I be so bold as to ask you how old you are?
please is there no way i can insert the uppercase get line in this mystr = toupper(mystr); am still very new and don't really know much about looping. Please just give me full illustration of how it look like if i want the upquote.txt to be in uppercase.
please just state it out like kemort did. Thank you
closed account (48T7M4Gy)
Use a for loop to go through each character in the string. If you don't know what that is then use the tutorial here under the section called The for loop.

http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.