Project help

I have no idea how to make words from the end to the beginning. So far I've done this...
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

#include <iostream>
#include <string>
#include <fstream>
#include <cctype>

using namespace std;

const string vowels = "aeiou";
string removeVowels (const string &str);
bool IsVowel (char chr);

int main () {

	string stri = "Uspeshno vnesuvanje na tekst vo fajl. \nBrishenje na samoglaski od fajl. \nDomashna po programiranje.";


	ofstream myFile("D:\domashna.txt", ios::out);
	myFile<<stri;
	myFile.close();


		
	ifstream dac;
	dac.open("D:\domashna.txt", ios::in);
	if(dac.is_open()) //{ 
	//	while (!dac.eof()) {
	

			cout<<"Orginalniot fajl.\n"<<endl;
			cout<<stri;
			cout<<"\n\n\n\n";
		
		cout<<"Orginalniot fajl bez imenki.\n"<<endl;
		cout<<removeVowels(stri);
	//}
	//}
		dac.close();


		ofstream domashna;
		domashna.open("D:\domashna_2.txt", ios::out);
		domashna<<removeVowels(stri);
		domashna.close();
	
		

	cin.get(); cin.get(); 
	return 0;
}



string removeVowels(const string &str)
{

	string finalString;

	for(int i = 0; i < str.size(); i++)
	{

		if(!(IsVowel(tolower(str[i]))))
		{
	
			finalString += str[i];
		}
	}
    

	return finalString;
}


bool IsVowel(char chr)
{

	for(int i = 0; i < 5; i++)
	{
		
		if(chr == vowels[i])
	
		return true;
	}
    

	return false;
}

Maybe you want something like this?
1
2
3
4
5
6
7
8
9
10
11
12
dac.open("D:\domashna.txt", ios::in);
while (std::getline(dac, stri))
{
	cout<<"Orginalniot fajl.\n"<<endl;
	cout<<line;
	cout<<"\n";
		
	cout<<"Orginalniot fajl bez imenki.\n"<<endl;
	cout<<removeVowels(stri);
}

dac.close();
:)) no man, i want to have 2 files, one with vowels, one without. I don't know how to do this.

This is a string. ----> string a is This. I want 2nd file to be without vowels and backwards.
Nobody? :)
Its not best solution but its better then nothing:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <vector>
#include <string>

int main()
{
	const std::string vowel = "aeiou";
	std::string str = "This is a test.";
	std::string result;
	for(unsigned int i = 0; i < str.size(); ++i)
	{
		bool notVowel = true;
		for(unsigned int j = 0; j < vowel.size(); ++j)
		{
			if(str[i] == vowel[j])
			{
				notVowel = false;
			}
		}
		if(notVowel)
		{
			result += str[i];
		}
	}

	std::cout << result << std::endl;

	std::vector<std::string> v;
	while(1)
	{
		std::string temp;
		unsigned int pos = result.find_first_of(' ');
		if(-1 == pos)
		{
			temp = result.substr(0, pos);
		    v.push_back(temp);
			break;
		}
		temp = result.substr(0, pos);
		v.push_back(temp);
		result.erase(0, pos + 1);
	}

	std::vector<std::string>::reverse_iterator rb(v.begin());
	std::vector<std::string>::reverse_iterator re(v.end());
	while(re < rb)
	{
		std::cout << *re++ << " ";
	}
	std::cout << std::endl;
	
	std::cout << "Press enter to exit...";
	std::cin.get(); 
	return 0;
} 


It prints string without vowels and backwards. You have to provide in/out from file.
Last edited on
Topic archived. No new replies allowed.