Question

In: Computer Science

please code in c language and follow all instructions and sample run. Simone works for a...

please code in c language and follow all instructions and sample run.

Simone works for a group that wants to register more people to vote. She knows her team can only ask a
certain number of people at any given time since they have other obligations. She has asked you to create a
program for her team that allows the user to type in how many people they want to ask at one time (the
duration of the current program run). The program will then ask that many people (see sample run). If a
person answers y, his or her name is added to a registration list (a file) and the current registration list is
output to screen. If they answer n, Ok is output to screen and the program continues. Once at least 10 people
have been registered, whenever the program is opened the phrase Target Reached! Exiting… should be
output to screen.
Step 1: You will be defining the following two functions (DO NOT MODIFY THE DECLARATIONS):
/*This function takes a file pointer, goes through the file and prints the file contents to screen. It returns the
number of lines in the file*/
int registered(FILE *fp)
/*This function takes a file pointer and adds a new line to the file*/
void new_register(FILE *fp)
Step 2: Use the functions you defined to make a working program.
Sample Run:
computer$ gcc –o vote vote.c
computer$ ./vote register.txt
***Registered so far:***
How many people to ask right now?
3
-Person 1: Would you like to register to vote?
n
Ok.
-Person 2: Would you like to register to vote?
y
Enter name: Bill Gates
Adding: Bill Gates
***Registered so far:***
1. Bill Gates
-Person 3: Would you like to register to vote?
y
Enter name: Mark Zuckerberg
Adding: Mark Zuckerberg
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
3 people asked! Taking a break.
computer$ ./vote register.txt
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
How many people to ask right now?
4
-Person 1: Would you like to register to vote?
n
Ok.
-Person 2: Would you like to register to vote?
n
Ok.
-Person 3: Would you like to register to vote?
y
Enter name: Jeff Bezos
Adding: Jeff Bezos
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
3. Jeff Bezos
-Person 4: Would you like to register to vote?
y
Enter name: Susan Wojcicki
Adding: Susan Wojcicki
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
3. Jeff Bezos
4. Susan Wojcicki
4 people asked! Taking a break.

Solutions

Expert Solution

#include<stdio.h>
char names[100],chr ;
int people,i=0,lines = -1,out,c=0;
char response='y';
FILE *fp;
char currentName[100];

void registered();

int main(){
printf("How many people to ask right now? ");
scanf("%d",&people);
fp = fopen("vote register.txt","w");
fputs("***Registered so far.***\n",fp);

while(i!= people){
printf("People %d:", i+1);
printf("Would you like to register for vote?");
scanf("%c",&response);
if(response == 'y'){
printf("Enter your first name:");
scanf("%s", &names);
fputs(names, fp);
new_register();
i += 1;
}
if(response == 'n')
i += 1;
}
printf("%d people asked. Take a break. \n",people);
registered();
printf("\nNumber of people registered %d",lines);
}
void new_register(){
fputs("\n", fp);
}
void registered(){
fclose(fp);
fp = fopen("vote register.txt", "r");

chr = getc(fp);

while (chr != EOF)
{
printf("%c", chr);
if (chr == '\n')
{
lines =lines + 1;
}
chr = getc(fp);
}
}


Related Solutions

Please follow the instructions carefully and complete the code given below. Language: Java Instructions from your...
Please follow the instructions carefully and complete the code given below. Language: Java Instructions from your teacher: (This is a version of an interview question I once saw.) In this problem, we will write a program that, given an integer k, an integer n, and a list of integers, outputs the number of pairs in in the list that add to k. To receive full credit for design, your algorithm must have a runtime in O(n) , where n is...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
in c++ please follow instructions and fix the errors and please make a comment next to...
in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix. Below are 25 code fragments, inserted into a try catch block. Each line has zero or more errors. Your task is to find and remove all errors in each fragment. Do not fix problems by simply deleting a statement; repair the problems by changing, adding, or deleting a few characters. There may be different ways to fix them You...
Write the basic JAVA code for the beginners and follow all the instructions listed 1. A...
Write the basic JAVA code for the beginners and follow all the instructions listed 1. A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for e.g., 1980), except that it is not a leap year if it is also divisible by 100 (for e.g., 1900); however, it is a leap year if it is further divisible by 400 (for e.g., 2000). Write a program that prompts the...
Translate the C function code below to the MIPS True Assembler Language code (machine instructions only)....
Translate the C function code below to the MIPS True Assembler Language code (machine instructions only). The function code should follow the conventions for MIPS function calls including passing parameters and returning results. Your function code must be written with the minimum number of machine instructions to be executed and without any use of MIPS pseudo-instructions. Myfunction(unsigned int a, unsigned int b, unsigned int c) { int i=0; while (a > c) { a /= b; i++; } return i;...
Please follow the instructions and solve it by c++ Close the project and create a new...
Please follow the instructions and solve it by c++ Close the project and create a new one called 'Lab0-Part3' with the same options as in the previous step. Write a C++ program that does the following: Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values. Prints both of the new arrays to the console.
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Please convert This java Code to C# (.cs) Please make sure the code can run and...
Please convert This java Code to C# (.cs) Please make sure the code can run and show the output Thank you! Let me know if you need more information. Intructions For this assignment you will be creating two classes, an interface, and a driver program: Class Calculator will implement the interface CalcOps o As such it will implement hexToDec() - a method to convert from Hexadecimal to Decimal. Class HexCalc will inherit from Calculator. Interface CalcOps will have abstract methods...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following:...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following: (1) the client and the server source files each (2) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identifiers suitable, to enable enhanced readability of the code. Problem: Write an ftp client and an ftp server such that the client sends a request to ftp server for downloading a file. The...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the following: 1) Your .cpp file of the solution. 2) For what n value (approximately) does your computer stop producing output? Why is this? Enter your answer in the 'Comments' field when you submit the file.   So far in our study of recursion we identified a few common recursive number sequences, such as the Fibonacci numbers. Number sequences like this are not recursive algorithms themselves...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT