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
Who invented the Graphical User Interface (GUI)?
GaryK [48]

Xerox PARC by Alan Kay, Douglas Engelbart, and a group of other researchers in 1981.

3 0
3 years ago
Help?!<br> Does anyone know how to use Adobe SoundBooth?
Mandarinka [93]
Never heard of that but it probably just have the kind of use of abobe flash
7 0
3 years ago
Read 2 more answers
Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, s
Afina-wow [57]

The code is implemented based on the given operations.

Explanation:

#include <iostream>

#include <string>

using namespace std;

class dayType

{ private:

 string day[7];

 string presentDay;

 int numofDays;

public:

 void setDay(string freshDay);

 void printDay() const;

 int showDay(int &day);

 int nextDay(int day);

 int prevDay(int day) const;

 int calcDay(int day, int numofDays);    

 dayType()

 {

  day[0] = "Sunday";

  day[1] = "Monday";

  day[2] = "Tuesday";

  day[3] = "Wednesday";

  day[4] = "Thursday";

  day[5] = "Friday";

  day[6] = "Saturday";

  presentDay = day[0];

  numofDays = 0;

 };

 ~dayType();

};

#endif

#include "dayType.h"

void dayType::setDay(string freshDay)

{

  presentDay = freshDay;

}

void dayType::printDay()

{

  cout << "Day chosen is " << presentDay << endl;

}

int dayType::showDay(int& day)

{

  return day;

}

int dayType::nextDay(int day)

{

day = day++;

if (day > 6)

 day = day % 7;

switch (day)

{

case 0: cout << "The successive day is Sunday";

 break;

case 1: cout << "The successive day is Monday";

 break;

case 2: cout << "The successive day is Tuesday";

 break;

case 3: cout << "The successive day is Wednesday";

 break;

case 4: cout << "The successive day is Thursday";

 break;

case 5: cout << "The successive day is Friday";

 break;

case 6: cout << "The successive day is Saturday";

 break;

}

cout << endl;

return day;

}

 

int dayType::prevDay(int day)

{

day = day--;

switch (day)

{

case -1: cout << "The before day is Saturday.";

 break;

case 0: cout << "The before day is Saturday.";

 break;

case 1: cout << "The before day is Saturday.";

 break;

case 2: cout << "The before day is Saturday.";

 break;

case 3: cout << "The before day is Saturday.";

 break;

case 4: cout << "The before day is Saturday.";

 break;

case 5: cout << "The before day is Saturday.";

 break;

default: cout << "The before day is Saturday.";

}

cout << endl;

return day;

}

int dayType::calcDay(int addDays, int numofDays)

{

addDay = addDays + numofDays;

if (addDay > 6)

 addDay = addDay % 7;

switch(addDay)

{

case 0: cout << "The processed day is Sunday.";

 break;

case 1: cout << "The processedday is Monday.";

 break;

case 2: cout << "The processedday is Tuesday.";

 break;

case 3: cout << "The processedday is Wednesday.";

 break;

case 4: cout << "The processedday is Thursday.";

 break;

case 5: cout << "The processedday is Friday.";

 break;

case 6: cout << "The processedday is Saturday.";

 break;

default: cout << "Not valid choice.";

}

cout << endl;

return addDays;

}

4 0
2 years ago
Which list method allows elements in a sequence to be removed and added at either end of the structure?
Amanda [17]

Answer:

b) queue

Explanation:

Queue is also an abstract data type or a linear data structure, just like stack data structure, in which the first element is inserted from one end called the REAR(also called tail), and the removal of existing element takes place from the other end called as FRONT(also called head).

4 0
3 years ago
Read 2 more answers
1. What does the term 'in season' mean?
yKpoI14uk [10]
Available at the time of year.
8 0
2 years ago
Read 2 more answers
Other questions:
  • What is the formula for calculating the average of cells<br> C2 through C30?
    15·1 answer
  • If a storm is 7.5 kilometers away, how much time is expected between observations of lightning and thunder? Round your answer to
    10·1 answer
  • The ____ file permission category in unix/linux systems typically entails all permissions and is designated by the letter u.
    7·1 answer
  • Place the steps in order to keep a graphic from spilling over into the next page and to include the text it is assciated with.
    12·1 answer
  • A chef writing up her famed recipe for beef stew realizes she has switched parsley and oregano everywhere in the recipe. The che
    13·1 answer
  • CAD workstations
    11·1 answer
  • How important is the mail merge feature of microsoft word in different organization.?
    8·2 answers
  • Project manager George is defining project management to his team. How should he define project management in one sentence?
    7·1 answer
  • 1) Using the density equation d=m/V: What is the density of a piece of metal with a mass o
    10·1 answer
  • The IPv6 address for an Ethernet connection begins with FE80::/64. What does this tell you about the address
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!