0% found this document useful (0 votes)
44 views8 pages

Operasifile

Uploaded by

Farhan Karisma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views8 pages

Operasifile

Uploaded by

Farhan Karisma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Nama : Farhan Karisma

NPM : 140810220042

Operasi File

1.

#include <iostream>
#include <fstream>

using namespace std;


void readText(string &a)
{
getline(cin, a);
}

void addToFile(string &a, string &b)


{
ofstream fileText;
fileText.open(a, ios::app);
fileText << b << endl;
fileText.close();
}

void checkVK(string &a, string &b)


{

int PanjangText = b.length();


int JumlahVokal = 0;
int JumlahKonsonan = 0;
int i = 0;

ifstream fileText;
fileText.open(a);
while(i < b.length())
{
if((b[i] == 'a')||(b[i] == 'A')||
(b[i] == 'i')||(b[i] == 'I')||
(b[i] == 'u')||(b[i] == 'U')||
(b[i] == 'e')||(b[i] == 'E')||
(b[i] == 'o')||(b[i] == 'O'))
{
JumlahVokal += 1;
}
else if(b[i] == ' ')
{}
else
JumlahKonsonan += 1;
i++;
}
cout << "Jumlah Huruf Vokal : " << JumlahVokal << endl
<< "Jumlah Huruf Konsonan : " << JumlahKonsonan << endl;
fileText.close();
}

int main ()
{
cout <<"Masukkan Nama File : ";
string fileName;
readText(fileName);
cout <<"Masukkan Isi File : ";
string dataFill;
readText(dataFill);

addToFile(fileName, dataFill);
checkVK(fileName, dataFill);

return 0;
}

2.

#include <iostream>
#include <fstream>

using namespace std;


void readText(string &a)
{
getline(cin, a);
}

void readChar(char &a)


{
cin >> a;
}

void addToFile(string &a, string &b)


{
ofstream fileText;
fileText.open(a, ios::app);
fileText << b << endl;
fileText.close();
}
void specificChar(string &a, char &b, int &c, int &d)
{
if((b == 'a')||(b == 'A'))
{
if((a[d] == 'a')||(a[d] == 'A'))
c += 1;
}
else if((b == 'b')||(b == 'B'))
{
if((a[d] == 'b')||(a[d] == 'B'))
c += 1;
}
else if((b == 'c')||(b == 'C'))
{
if((a[d] == 'c')||(a[d] == 'C'))
c += 1;
}
else if((b == 'd')||(b == 'D'))
{
if((a[d] == 'd')||(a[d] == 'D'))
c += 1;
}
else if((b == 'e')||(b == 'E'))
{
if((a[d] == 'e')||(a[d] == 'E'))
c += 1;
}
else if((b == 'f')||(b == 'F'))
{
if((a[d] == 'f')||(a[d] == 'F'))
c += 1;
}
else if((b == 'g')||(b == 'G'))
{
if((a[d] == 'g')||(a[d] == 'G'))
c += 1;
}
else if((b == 'h')||(b == 'H'))
{
if((a[d] == 'h')||(a[d] == 'H'))
c += 1;
}
else if((b == 'i')||(b == 'I'))
{
if((a[d] == 'i')||(a[d] == 'I'))
c += 1;
}
else if((b == 'j')||(b == 'J'))
{
if((a[d] == 'j')||(a[d] == 'J'))
c += 1;
}
else if((b == 'k')||(b == 'K'))
{
if((a[d] == 'k')||(a[d] == 'K'))
c += 1;
}
else if((b == 'l')||(b == 'L'))
{
if((a[d] == 'l')||(a[d] == 'L'))
c += 1;
}
else if((b == 'm')||(b == 'M'))
{
if((a[d] == 'm')||(a[d] == 'M'))
c += 1;
}
else if((b == 'n')||(b == 'N'))
{
if((a[d] == 'n')||(a[d] == 'N'))
c += 1;
}
else if((b == 'o')||(b == 'O'))
{
if((a[d] == 'o')||(a[d] == 'O'))
c += 1;
}
else if((b == 'p')||(b == 'P'))
{
if((a[d] == 'p')||(a[d] == 'P'))
c += 1;
}
else if((b == 'q')||(b == 'Q'))
{
if((a[d] == 'q')||(a[d] == 'Q'))
c += 1;
}
else if((b == 'r')||(b == 'R'))
{
if((a[d] == 'r')||(a[d] == 'R'))
c += 1;
}
else if((b == 's')||(b == 'S'))
{
if((a[d] == 's')||(a[d] == 'S'))
c += 1;
}
else if((b == 't')||(b == 'T'))
{
if((a[d] == 't')||(a[d] == 'T'))
c += 1;
}
else if((b == 'u')||(b == 'U'))
{
if((a[d] == 'u')||(a[d] == 'U'))
c += 1;
}
else if((b == 'v')||(b == 'V'))
{
if((a[d] == 'v')||(a[d] == 'V'))
c += 1;
}
else if((b == 'w')||(b == 'W'))
{
if((a[d] == 'w')||(a[d] == 'W'))
c += 1;
}
else if((b == 'x')||(b == 'X'))
{
if((a[d] == 'x')||(a[d] == 'X'))
c += 1;
}
else if((b == 'y')||(b == 'Y'))
{
if((a[d] == 'y')||(a[d] == 'Y'))
c += 1;
}
else if((b == 'z')||(b == 'Z'))
{
if((a[d] == 'z')||(a[d] == 'Z'))
c += 1;
}
else
{}
}

void checkChar(string &a, string &b, char &c)


{

int textLength = b.length();


int charAmount = 0;
int i = 0;
ifstream fileText;
fileText.open(a);
while(i < b.length())
{
specificChar(b, c, charAmount, i);
i++;
}
cout << "Characters of " << c << " : " << charAmount << endl;
fileText.close();
}

int main ()
{
string fileName;
readText(fileName);
string dataExample = "Saya Adalah Mahasiswa Teknik Informatika Universitas
Padjadjaran.";
char charToCheck;
readChar(charToCheck);

addToFile(fileName, dataExample);
checkChar(fileName, dataExample, charToCheck);

return 0;
}

4.

#include <iostream>
#include <fstream>

using namespace std;

void inputan(int &b)


{
cout << "Pergeseran: ";
cin >> b;
}

void baca_file(string &data)


{
ifstream nfile;
nfile.open("Enkripsi.txt");

getline(nfile, data);
nfile.close();
}
void proses_enkripsi(string data, int b)
{
char enkripsi;
string hasilEnkripsi;
int asciiZ = 90;

for (int i = 0; i <= data.size() - 1; i++)


{
if (isalpha(data[i]))
{
enkripsi = data[i] + b;

if (enkripsi >= asciiZ)


{
enkripsi -= 26;
}

hasilEnkripsi += enkripsi;
}
else
{
hasilEnkripsi += data[i];
}
}

cout << hasilEnkripsi;

int main()
{
string data;
int pergeseran;

inputan(pergeseran);
baca_file(data);
proses_enkripsi(data, pergeseran);

return 0;
}
https://www.youtube.com/watch?v=eZtwE5JR2ZA

You might also like