Write a C program that will act as a database access tool.
Three separate functions are needed to:
1. Print dates
2. Print names
3. Print category numbers and the average of the numbers.
A random text file (from notepad) is supplied for the dates, names, and category's.
For Example:
Storm name: Storm Date: Storm category number:
The program must ask the user which of the three items listed above they want to run instead of dumping all of the information at once.
Code:
#include<stdio.h>
#include<string.h>
void print_dates(char line[][128], int cnt)//prints dates
{
int i, j;
for(i=0;i<cnt;i++)
{
for(j=0;line[i][j]!='\0';j++)
{
if(line[i][j]!='
') printf("%c",line[i][j]);//print characters until there's a
space
else
break;
}
printf("\n");
}
}
void print_names(char line[][128], int cnt)
{
int i, j;
for(i=0;i<cnt;i++)
{
for(j=0;line[i][j]!='\0';j++)
{
if(line[i][j]=='
') break;//skip until a space is encountered
}
j++;
for(;line[i][j]!='\0';j++)
{
if(line[i][j]!='
') printf("%c",line[i][j]);//print thereafter
else
break;
}
printf("\n");
}
}
void print_numbers(char line[][128], int cnt)
{
int i, j;double avg = 0;
for(i=0;i<cnt;i++)
{
double total = 0;//stores number in
every line
for(j=0;line[i][j]!='\0';j++)
{
if(line[i][j]=='
') break;//skip until two spaces are encountered
}
j++;
for(;line[i][j]!='\0';j++)
{
if(line[i][j]=='
') break;
}
j++;
for(;line[i][j]!='\0';j++)
{
if(line[i][j]!='\n')
{
printf("%c",line[i][j]);//print the rest
characters
total = (total * 10) + (line[i][j] -
'0');//characters to number
}
else
break;
}
avg += total;//sum all the
numbers
printf("\n");
}
avg = avg/cnt;//calculate average
printf("Average: %lf\n", avg);
}
int main()
{
FILE *fp = fopen("example.txt","r");//open file
char line[100][128];int cnt = 0, i = 0;//line stores
file's contents, cnt stores no. of lines in the file
while(fgets(line[i++], sizeof line, fp) != NULL)
{
cnt++;
}
printf("Which item do you want, Date, Name or Number:
");
char inp[200];scanf("%s",inp);
if(strcmp(inp,"Date") == 0)
{
print_dates(line, cnt);
}
else if(strcmp(inp, "Name") == 0)
{
print_names(line, cnt);
}
else if(strcmp(inp, "Number") == 0)
{
print_numbers(line, cnt);
}
else
{
printf("You have entered an invalid
option\n");
}
return 0;
}
Output:
Write a C program that will act as a database access tool. Three separate functions are...
C++ Functions & Streams Write a program that will demonstrate some of the C++ Library Functions, Stream Manipulators, and Selection Control Structures. The user will be given a menu of four choices. They can input a 1 for finding Cosines, 2 for finding Logarithms, 3 for converting between Decimal and Hexadecimal, or 4 to change the format of a cstring date. You must use the proper functions and/or stream manipulators to find the answers. If the user picks the cosine,...
Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
**IN C*** * In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...
USING C++ PROGRAM Instructions - Part C Write a program that has three functions: All characters printed should be in White ► Call the first function from main().Print "I'm in main" (as shown in example) > Print "I'm in function 1" in the first function. Call the second function. ► Print "I'm in function 2” in the second function and then ask the user to enter a float value. Enter 25 Call a third function and pass the value to...
Write a C program requesting the user to input two integer numbers and then requesting the user to either add, subtract, or multiply the two numbers (choose 0 to add, 1 to subtract, or 2 to multiply. Declares three separate functions for these choices to come after main(). Program needs to use a pointer to these three functions to perform the requested action. Must print to output.
8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...
Ask user to enter three numbers (a,b,c). Write a program (c++) that will print the value to the following equations: a. maximum value of one of these equations (functions separated by commas) (a, a+b, a-c) + maximum of (b, 2b-c, b+2a) b. maximum value of (3, c+3a, 0) + minimum of (ab-2, 3c, ac) Define functions max and min which will accept 3 numbers as arguments and return the mix and min of them correspondingly. Use these functions in order...
Part I - Functions Write a program to do the following: • . Create two separate lists: ["Female", "M", 1, 4, "Mail", 0, "F"] o [-23,1,35,52,23,0,1000] For each element in the first list, replace each element using the following rules: o Change the value to Female if the element is Female, F, or 1 o Change the value to Male if the element is Male, M, or 0 o Otherwise, change it to "Undefined" For each number in the second...
c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...