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
love history [14]
3 years ago
12

25 pts) Level 1 Programming Task Write the function getPop(char myCode[3]), which takes in a two-digit string representing the s

tate or territory code and returns the associated state or territory population. The function should open and scan the file USpops.txt for the input two-digit code, myCode. If myCode is not found in the file, the function should return -1. Make sure to close the file once the file reading is complete.
Computers and Technology
1 answer:
exis [7]3 years ago
5 0

Answer:

The method definition to this question can be defined as follows:

int getPop(char myCode[3])//defining a method getPop that takes char array in its parameter

{

FILE* f = NULL;//defining a pointer variable

int pop;//defining integer variable

char s_code[2];//defining char array state_code

char s_name[100];//defining char array stateName

f = fopen("state", "r");//using pointer variable that use fopen method for open file

if(f == NULL)//defining if block that check file is empty

{

return -1;//return value -1

}

while(!feof(f))//defining while loop for input value in file

{

fscanf(f, "%s %s %d",s_code, s_name, &pop);//input value

if(strncmp(myCode, s_code, 2) == 0)//use if block to compare string value

{

printf("Population for %s: %d", s_name, pop);//print value

return 0;//return 0

}

}

fclose(f);//close file

return 0;

}

Explanation:

In the above code, a method "getPop" is defined that accepts a character array "myCode" in its parameter, and inside the method, one pointer variable "f", one integer variable "pop", and two char array "s_code and s_name" is declared.

In the method firstly fopen method is used that holds a file and use if block to check it is not empty, if the condition is true it will give a value that is "-1".

In the next step, a while loop is declared, that input value and use if block to compare string value, and return 0, and at the last, it closed the file.    

You might be interested in
Don't click on this I am testing
Andrew [12]

Don't click on this I am testing... I want the points so.

3 0
3 years ago
Read 2 more answers
Debate whether social networking is harmful or helpful to society.
Dmitriy789 [7]

Answer:

I believe that Social Networking <em>IS </em>helpful to society, but, people use it for wrong stuff.

5 0
2 years ago
Write a program that include a method that returns the sum of all the elements of a Linked List of Integers. Allow the user to e
Illusion [34]

Answer:

static void Main(string[] args)

       {

           //declare a blank linked list

           LinkedList<int> numList = new LinkedList<int>();

           Console.WriteLine("Enter the Numbers");

           //check if the size of the linkedlist is 10

           while(numList.Count < 10)

           {

               //read the input supplied by the user

               string val = Console.ReadLine();

               //check if the input is integer

               if(int.TryParse(val, out _) == false)

               {

                   //if not integer, display error message and prompt for new number

                   Console.WriteLine("Invalid number");

                   continue;

               }

               //add the inputted number to the linkedlist

               numList.AddLast(int.Parse(val));

               

           }

           //call the method for linkedlist sum and display it

           Console.WriteLine(SumLinkedList(numList));

           Console.Read();

       }

       //method for linkedlist summation

       private static int SumLinkedList(LinkedList<int> val)

       {

           //declare sum as zero

           int sum = 0;

           //loop through the linkedlist to display the num and sum all numbers

           foreach(int item in val)

           {

               Console.Write(item + " ");

               sum += item;

           }

           return sum;

       }

   }

Explanation:

program written with c#

8 0
3 years ago
Microsoft, Intuit and, Yahoo are building new facilities in Quincy, WA, a town that previously had a population of 3,500. Along
sveticcg [70]

Answer:

Economic.

Explanation:

In the following scenario, In Quincy, WA, a community that formerly would have a community of 3,500, they are developing new infrastructure. In addition to such friends and neighbors, Quincy citizens will also be seeing more traffic signals, a shopping center, rising property prices, and new opportunities.

So, the following scenario is best suited for the economic changes.

5 0
4 years ago
A homeowner uses a smart assistant to set the house alarm, get packages delivery updates, and set time on the outdoor lights. Wh
ch4aika [34]

The example where the alarm of the house set up, delivery updated should be provided, etc should represent the function example of the artificial intelligence.

The following information related to artificial intelligence is:

  • It refers to the human intelligence where the machines could be treated as humans and according to this, the actions should be mimic.
  • It should be used for any kind of machine where the traits should be associated along with the mind of the human-like for learning & problem-solving purpose.

Therefore we can conclude that The example where the alarm of the house set up, delivery updated should be provided, etc should represent the function example of the artificial intelligence.

Learn more about the machine here: brainly.com/question/2555822

3 0
3 years ago
Other questions:
  • Which button is used to open the Start menu in Windows Vista?
    14·1 answer
  • Write a function all_cats that consumes a comma-separated string of animals and prints whether all of the animals have "cat" in
    12·1 answer
  • Write a program that displays a menu allowing the user to select air water, or steel. After the user has made a selection, the n
    10·1 answer
  • A process at Host C receiving two incoming UDP segments from two different hosts will know that they originated from two differe
    14·2 answers
  • Networking and telecommunications technologies, along with computer hardware, software, datamanagement technology, and the peopl
    11·1 answer
  •  Which device containing sensors send signals to the computer whenever light changes are detected? 
    11·1 answer
  • What happens when a user clicks Accept on a meeting request?
    9·2 answers
  • fun fact about London(me): when it comes to relationships she becomes clingy to the person shes dating
    10·1 answer
  • calculate how many turns of cable you will need on the drum for your cage and skip to move up and down by 500 m​
    12·1 answer
  • A(n) ________ address is the address that external entities use when communicating with your network.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!