Abdullah 23443212 Khaled 33433234 Mohammed 44544332 Notice you have no indicatio
ID: 3535563 • Letter: A
Question
Abdullah
23443212
Khaled
33433234
Mohammed
44544332
Notice you have no indication of how many names and numbers in the file info.txt
then will save all names on a file call it names.txt and all numbers on another file called numbers.txt
Names must be encrypted before saved on the names.txt file
encryption should be as follow:
Each character should be shifted twice the position of its location in the world +1
so for example if the word is: 'ali' it will be encrypted to 'bon' because:
'a' will be 'b' since its at zero location and twice zero +1 is 'b'
'l' will be 'o' since it is at location 1 and twice that location +1 is 3 so 'o'
and so on.
Explanation / Answer
#include<iostream.h>
#include<fstream.h>
struct info
{
char name[50];
int num;
};
void main()
{
fstream file,file1,file2;
file.open("info.txt");
file1.open("name.txt");
file2.open("number.txt");
info a;
char n[50];
int i,j;
while(file!=eof)
{
a=file.read((*ch)&a,sizeof(a));
for(i=0;a.name[i]!='';i++)
{
j=i+1;
name[i]=name[i]+j;
}
file1.write((*ch)&a.name,sizeof(a.name));
file2.write((*ch)&a.num,sizeof(a.num));
}
cout<<"name file contain ";
while(file1!=eof)
{
a.name=file1.read((*ch)&a.name,sizeof(a.name));
cout<<a.name<<" ";
}
cout<<"number file contain ";
while(file2!=eof)
{
a.num=file2.read((*ch)&a.num,sizeof(a.num));
cout<<a.num<<" ";
}
file.close();
file1.close();
file2.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.