Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C language with the following criteria. Name the program acco

ID: 3548233 • Letter: W

Question

Write a program in C language with the following criteria.


Name the program accounts.c, and turn it in to D2L by 11:59 p.m. on Tuesday, December 10th. Create and Open a file "accounts.txt" for writing. Generate one random integer number (random_count) between one and 100 using a seed. See the three paragraphs on pages 430 and 431 on how to generate a random number with a seed. To make sure the number is between 1 and 100, use random_count = 1 + remainder of the random number generated divided by 100. Display the random_count value on the screen. Use a for loop to generate random integer account numbers. Use the value in "random_count" to determine how many account numbers to generate. You do not have to use the 'seed' again for these numbers. Use a formula similar to the one above using the '%' operator again to only generate account numbers between 10000 and 99999. Write each number to the accounts.txt file. Display each number on the screen - NEATLY. Place each number into an array. Close the accounts.txt file. Ask the user what account number they would like to search for. Use a linear search function to find the number in the array. (See pages 402 & 403 for function's ' code and description of how to call it.) Display a message stating at which index the account number was found or that it was not found. Sort the contents of the array into ascending order. (See pages 403 - 405 for function's code and description.) NEATLY display the sorted contents of the array to the screen/monitor. Additional Requirements: The only global items that can be used are #define preprocessor directives. As always, be sure to include all required comments.

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX 100
// linear search function to search in array.
int linear_search(int account_array[],int random_count,int search_account_num)
{
    int i;
    // process for each and every value in array.
for(i=0; i<random_count; i++)
{
// if account was found return index
if(search_account_num==account_array[i])
{
return i;
}
}
// if code reached here means account was not found. return -1;
return -1;
}
// selection sort to sort account numbers.
void selectSort(int list[],int n)
{
int toFill,smallPos,pos,temp;
     //STEP 1: repeat each position toFill from 0 to n-2
for(toFill=0; toFill<=n-2; toFill++)
{
    //STEP 2.1:intialize smallPos to toFill
    smallPos = toFill;
    // STEP 2.2: repeat pos ranging from toFill to n-1
    for(pos = toFill; pos<=n-1; pos++)
    {
            //STEP 2.3: if list[pos] is smaller than list[smallPos]
        if(list[pos]<list[smallPos])
        //STEP 2.4 copy pos to smallPos
        smallPos = pos;
    } // end for
    // STEP 3: if smallPos not equal to toFill swap list[smallPos] to list[toFill]
    if(smallPos!=toFill)
    {
    temp = list[smallPos];
    list[smallPos] = list[toFill];
    list[toFill] = temp;
    }
} //end for
}
int main()
{
// FILE pointer to open file.
FILE* foutp;
// variable to hold random count
int random_count;
// array to hold account numbers.
int account_array[MAX],i;
// temporary variable to hold account number.
int account_num;
// variable to hold account number to search for.
int search_account_num;
// seed rand with null.
srand(time(NULL));
// variable to hold result of linear search.
int index;
// generating random _ count.
random_count = rand()%MAX + 1;
// open file to write.
foutp = fopen("accounts.txt","w");
// print random count generated.
printf("Random value genearated is %d",random_count);
// now start generating account numbers.
for(i=0; i<random_count; i++)
{
account_num = rand()%89999 + 10000;
// wirte to file account number/
fprintf(foutp,"%d ",account_num);
// print account number on to the screen
printf(" Account Number is : %d",account_num);
// put the same into array.
account_array[i] = account_num;
}
// close file.
fclose(foutp);
// ask the user account number to search for.
printf(" Enter account number to search for ");
scanf("%d",&search_account_num);
// call linear search fucntion to find account number found ornot.
index = linear_search(account_array, random_count, search_account_num);
// if account number was found print the index.number
if(index>=0)
printf(" Account was found at index: %d",index);
// print that account was not found.
else
printf(" Account was not found");
// call selection sort..
selectSort(account_array, random_count);
// now print account number
for(i=0; i<random_count; i++)
{
printf(" Account Number is : %d",account_array[i]);
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote