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
geniusboy [140]
3 years ago
6

Language: C

Computers and Technology
1 answer:
Vikentia [17]3 years ago
3 0

The .cpp code is avaiable bellow

Code:

#include <stdio.h>

#include <string.h>

int main()

{

    char **kW;

    char *fN;

    int nW = 0;

    kW = malloc(5000 * sizeof(char*));

    for (int i = 0; i<5000; i++)

    {

         kW[i] = (char *)malloc(15);

    }

    fN = (char*)malloc(25);

    int choice;

    while (1)

    {

         printf("1) File text to use as cipher\n");

         printf("2) Make a cipher with the input text file and save result as output file\n");

         printf("3) Decode existing cipher\n");

         printf("4) Exit.\n");

         printf("Enter choice: ");

         scanf("%d", &choice);

         if (choice == 1)

         {

             nW = readFile(kW, fN);

         }

         else if (choice == 2)

         {

             encode(kW, fN, nW);

         }

         else

         {

             Exit();

         }

         printf("\n");

    }

    return 0;

}

int readFile(char** words, char *fN)

{

    FILE *read;

    printf("Enter the name of a cipher text file:");

    scanf("%s", fN);

    read = fopen(fN, "r");

    if (read == NULL)

    {

         puts("Error: Couldn't open file");

         fN = NULL;

         return;

    }

    char line[1000];

    int word = 0;

    while (fgets(line, sizeof line, read) != NULL)

    {

         int i = 0;

         int j = 0;

         while (line[i] != '\0')

         {

             if (line[i] != ' ')

             {

                  if (line[i] >= 65 && line[i] <= 90)

                  {

                       words[word][j] = line[i]; +32;

                  }

                  else

                  {

                       words[word][j] = line[i];

                  }

                  j++;

             }

             else

             {

                  words[word][j] = '\n';

                  j = 0;

                  word++;

             }

             i++;

         }

         words[word][j] = '\n';

         word++;

    }

    return word;

}

void encode(char** words, char *fN, int nwords)

{

    char line[50];

    char result[100];

    if (strcmp(fN, "") == 0)

    {

         nwords = readFile(words, fN);

    }

    getchar();

    printf("Enter a secret message(and press enter): ");

    gets(line);    

    int i = 0, j = 0;

    int w = 0, k = 0;

    while (line[i] != '\0')

    {        

         if (line[i] >= 65 && line[i] <= 90)

         {

             line[i] = line[i] + 32;

         }

         w = 0;

         int found = 0;

         while (w<nwords)

         {

             j = 0;

             while (words[w][j] != '\0')

             {

                  if (line[i] == words[w][j])

                  {

                       printf("%c -> %d,%d \n", line[i], w, j);

                       found = 1;

                       break;

                  }

                  j++;

             }

             if (found == 1)

                  break;

             w++;

         }

         i++;

    }

    result[k] = '\n';

}

void Exit()

{

    exit(0);

}

You might be interested in
PLEASE HELP
Rainbow [258]

Explanation:

examples

Area= Side Squared

area =square root of 49cm Squared =Square root of S Squared

A=7cm Squared

6 0
3 years ago
Question # 7
mixer [17]

Answer:

A

Explanation:

4 0
3 years ago
The Baltimore Sun reported on a study by Dr. Sara Harkness in which she compared the sleep patterns of 6-month-old infants in th
lawyer [7]

(a) The standard error of the mean (SEM) for the U.S. babies is 0.083.

(b) An approximate 95% confidence interval for the mean sleep time for 6-month-old babies in the United States is 12.8367< μ1< 13.163.

(c) An approximate 95% for the difference in average sleep time for 6-month-old Dutch and U.S. infants is −2.203< μ1 <μ2 < −1.7969.

What is standard error and how it is measured?

A statistical concept known as the standard error uses standard deviation to assess how accurately a sample distribution represents a population. The standard error of the mean describes the statistical variation between a sample mean and the population's actual mean.

According to the given information:

In United States:

Sample size $\boldsymbol{n}_1=\mathbf{3 6}$

Mean, $\bar{x}_1=13$

Standard deviation, $s_1=\mathbf{0 . 5}$

In Netherlands:

Sample size, $n_2=66$

Mean, $\bar{x}_2=15$

Standard deviation, $s_2=\mathbf{0 . 5}$

(a) For the newborns in the United States, the standard error of the mean (SEM) is determined as follows:

$$\begin{aligned}& S E\left(\bar{x}_1\right)=\frac{s_1}{\sqrt{n_1}} \\& S E\left(\bar{x}_1\right)=\frac{0.5}{\sqrt{36}} \\& S E\left(\bar{x}_1\right)=0.083\end{aligned}$$

(b) The following formula is used to determine the 95% confidence interval for the mean sleep time for babies aged 6 months in the United States:

$$\bar{x}_1 \pm z_{0.05 / 2} \times \sqrt{\frac{s_1^2}{n_1}}$$

$$\begin{aligned}& 13 \pm 1.96 \times \sqrt{\frac{0.5^2}{36}} \\& 12.8367 < \mu_1 < 13.163\end{aligned}$$

(c) The 95% difference in the amount of time newborns in the Netherlands and the United States spend sleeping on average is computed as follows:

$$\begin{aligned}& \bar{x}_1-\bar{x}_2 \pm z_{0.05 / 2} \times \sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}} \\& (13-15) \pm 1.96 \times \sqrt{\frac{0.5^2}{36}+\frac{0.5^2}{66}} \\& -2.203 < \mu_1 < \mu_2 < -1.7969\end{aligned}$$

To know more about standard error:

brainly.com/question/29363195

#SPJ4

8 0
1 year ago
Which of the following is NOT an argument used to determine how a shot is fired from an A. object the shot itself being instanti
Firdavs [7]
C. The color of the shot...
7 0
3 years ago
Which DHCPv4 message will a client send to accept an IPv4 address that is offered by a DHCP server? (Points : 5) Unicast DHCPACK
gogolik [260]

Answer: Broadcast DHCPREQUEST

Explanation:

The DHCPv4 broadcast the DHCP REQUEST message by the client for accepting an IPv4 address which is basically offer by the server.

The DHCP REQUEST indicate that type of server that are basically chosen by the client for further interaction.

The DHCPREQUEST message basically used to notify that the client decline or accept the offer of server. In the DHCP protocol, it basically allow for broadcasting the individual destination in the network. The server basically sent the DHCP OFFER for receiving the DHCP REQUEST.

 

4 0
3 years ago
Other questions:
  • What type of data can we enter in a spreadsheet?
    11·1 answer
  • If you place a semicolon after the test expression in a while loop, it is assumed to be a(n) ________. a. pre-test loop b. post-
    9·1 answer
  • Which of the following are tasks you can
    12·2 answers
  • Sales representatives want to capture custom feedback record details related to each Account. The sales reps want to accomplish
    12·1 answer
  • Kris is the project manager for a large software company. Which part of project management describes the overall project in deta
    11·2 answers
  • LAB: Convert to binary - methods
    11·1 answer
  • The most important hardware device for connecting supercomputers over a wide area
    10·1 answer
  • Silas develops this algorithm to compute the calories burned for an activity for a given number of minutes and body weight: If t
    6·1 answer
  • The getElementById DOM Method do?
    13·1 answer
  • Explain briely what this statement mean.<br>"A byte is equivalent to a character"<br>​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!