1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nataly [62]
3 years ago
14

Write a new program called Lab7D that will read strings from a text file and turn them into "encrypted code". Create a bool func

tion called isVowel that accepts a character as a parameter and returns a true if it’s a vowel (aeiou) and false otherwise.

Computers and Technology
1 answer:
Aliun [14]3 years ago
5 0

Answer:

I am writing a C program for the first part and Python program for the second part of the question.    

<h2>1st program:</h2>

#include <stdio.h>  //to use input output functions

#include <stdlib.h>  // used here to access exit function

void main() {  //start of the main() function body

char fname[100], character;

// fname is the name of the input file which contains characters and character //variable is used to store characters

FILE *original, *temporary;  

/* two pointers of File type: original is used for the original input file and temporary is used for a temporary file name aux.txt */

printf("Enter the name of the text file to encrypt : ");

//prompts the user to enter the name of the file to be encrypted

scanf("%s",fname); //reads the name of the file from user

original=fopen(fname, "r"); //open the input file in read mode

if(original==NULL)  {

//displays the following message if the file is empty or does not exists

 printf("Cannot open original file");  

 exit(1);  }  //program exits

temporary=fopen("aux.txt", "w");

//creates a temporary file named aux.txt and open that file in write mode

if(temporary==NULL)  { //if temporary file could not be created

 printf("Cannot create a temporary file");

 fclose(original); //closes the original input file

 exit(2);  }  //program exits

while(1)  {

 character=fgetc(original);  

/*pointer original moves through the input file and gets input from original input file one character at a time and store it in character variable */

 if(character==EOF)  

//when all characters are obtained and pointer is at end of file  {

  break;  //the loop breaks }

 else   {  //if EOF is not yet reached

  character=character+100;  

//add 100 to each character to encrypt the characters

  fputc(character, temporary);

 // fputc() writes a single character at a time to aux file } }

fclose(original);  //closes input file

fclose(temporary); //closes aux file

original=fopen(fname, "w");  //opens input file in write mode

if(original==NULL) { //if file does not exist display following message

 printf("Cannot open the original file to write");

 exit(3);  } //program exits

temporary=fopen("aux.txt", "r"); //open aux.txt file in read mode

if(temporary==NULL)  { //if pointer temporary is NULL

 printf(" Cannot open temporary file to read");

 fclose(original);  //closes input file

 exit(4);  } //program exits

while(1)  {

 character=fgetc(temporary);

//obtains every character from aux file pointed by temporary

 if(character==EOF)  //if end of file is reaced {

  break;   } //the loop breaks

 else   { //if end of file is not reached

  fputc(character, original);  

//puts every character to input file }  }

printf(" %s is encrypted \n", fname);  

//displays this message when input file is successfully encrypted

//closes input and aux text files

fclose(original);

fclose(temporary); }  

Explanation:

The program first asks the user to enter the name of the file. Then the program uses two pointers original for input file and temporary for aux text file. It first opens the file whose name is entered by the user and reads that file by getting each single character using fgetc() until the pointer reaches the end of the file. While reading each character of the input file, it encrypts every character using and puts that encrypted content in temporary file names aux.txt using fputc() until the pointer reaches the end of the file. Lastly all the encrypted strings of the are placed in the original input text file.

<h2>Second program:</h2>

# bool function that accepts character as parameter and returns true if its a #vowel and false otherwise

def isVowel(character):  

   if character.lower() in 'aeiou':  #converts uppercase char to lowercase

       return True  #return true if character is a vowel    

   else:

       return False #returns false if input character is not a vowel

The program has a function isVowel() which takes a character as a parameter to check if that character is a vowel. If character is in uppercase  letters, it handles these characters using lower() method to convert the character to lowercase and then returns true if that character is a vowel otherwise returns false. To check the working of the function you can replace True and False with print statement such as:

if character.lower() in 'aeiou':

       print("It is a vowel")

   else:

       print("It is not a vowel")

And after that you can call this function and pass a character to it as:

isVowel('i')

You might be interested in
WHICH OF THESE IS A TYPE OF ETHERNET <br> 802.11AC <br> 1000BASET <br> 4G
Kobotan [32]

Answer:

1000BaseT

Explanation: Just took the quiz and got it right!

1000BaseT is specific to Ethernet

802.11ac is a type of WiFi connection (even though it uses Ethernet)

4G is what they use to provide cell phone service

6 0
3 years ago
Which one is not the part of motherboard ?<br>O Registers<br>O<br>Bus<br>O<br>Port<br>O<br>none​
Svetradugi [14.3K]

Answer:

can you expand on your question?

5 0
3 years ago
Ask how many apples the user wants. Ask how many people the user will share the apples with. Find out how many apples will remai
Sati [7]

Answer:

The program in Python is as follows:

apples = int(input("Apples: "))

people = int(input("People: "))

apples%=people

print("Remaining: ",apples)

Explanation:

This gets the number of apples

apples = int(input("Apples: "))

This gets the number of people to share the apple

people = int(input("People: "))

This calculates the remaining apple after sharing the apple evenly

apples%=people

This prints the calculated remainder

print("Remaining: ",apples)

5 0
3 years ago
A user reports network resources can no longer be accessed. The PC reports a link but will only accept static IP addresses. The
Aloiza [94]

Answer: is this a real question but I think it would be Ip address hope this helps :)))

Explanation:

3 0
2 years ago
In terms of resource utilization, a /an application may require higher local
aksik [14]

Answer: A) Installed

Explanation: Installed application work on the system on which they are installed .They are supposed to persist the required speed of processing to execute the task ,enough memory and other resources as well to fulfill the need of the application functioning.

Other option is incorrect because cloud based application run with help of internet service via web browser so they resources in this applications based on the internet connectivity and browser's speed .Thus, the correct option is option(A).

3 0
3 years ago
Other questions:
  • I need help please?!!!
    15·1 answer
  • The syntax for multiplication function is ____________.
    8·1 answer
  • Do you think that people have a “right” to remain anonymous online? Why or why not?
    6·1 answer
  • RFID tags uses memory that is read-only.A. TrueB. False
    5·1 answer
  • Translate the following C++ program to MIPS assembly program. *Please explain each instruction of your code by a comment and sub
    5·1 answer
  • Write a function to reverse a given string. The parameter to the function is a string. Function should store the reverse of the
    12·1 answer
  • In order to get a comprehensive evaluation of the computer programmers he managed, Justin organized a(n) __________, where he as
    11·1 answer
  • How do you convert an algorithm to make it possible for a computer to read
    6·1 answer
  • One limitation of high-level programming languages is
    10·1 answer
  • Read each of the following statements about Computer Science and explain why you think that statement is true.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!