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

Design and write a computer program as a Win32 console application in C to store

ID: 3684195 • Letter: D

Question

Design and write a computer program as a Win32 console application in C to store a list of names (tin* Iasi name first) and ages in parallel arrays, and then later to sort them into alphabetical order, keeping the ages with the correct names. See Programming Projects 6. in Chapter S of the textbook for a typical Sample output. The name of your source program shall be p5.c and that of your executable program shall be p5.exe. Your program shall receive information from the user as a command-line argument. For example, a typical command line to start your program (from a command prompt) might be L: >p5 peoplefile. txt Your program shall NOT seek information from the user such as by a call to scanf(). Your program shall NOT print information to the screen except as required herein. If your program is started without any command-line arguments, it shall print the following line to the screen and terminate execution: EE 233 Spring 2016 P5, , (Fill in your real name in place of and he sure to follow the output with a newline.) If your program is started with at least one command-line argument, it shall NOT print the line given above but shall proceed with normal execution. The first command-line argument (after the program name itself) will be the name of the text file for your program to read. No line in this file will contain more than 80 characters. If the file supplied as a command-line argument cannot be opened, your program shall write an error message to the screen, and terminate execution. In a similar manner, your program shall properly handle all error conditions that might arise. Your program shall read the input text file and scan the names and ages for storage in separate arrays. The names array(s) shall store strings, and ages shall store integers. A word (string) is defined as a sequence of characters that is bounded by white space (tab. newline, or space characters). A string will be no longer than 40 characters. Your program shall be able to scan at least 100 names and the corresponding ages. If more than 100 names and ages are in the input file, your program shall print an error message saying that more than 100 lines of data have been encountered, and terminate execution, without processing that file. After your program has read and processed the entire file, it shall print, with an appropriate header, the alphabetized list of names and ages (see the textbook for a sample output), only. Be sure to follow the output with a newline, and do not print the original list from the input file.

Explanation / Answer

Can help you with this:

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define CLASS_SIZE 3
#define NAME_LEN 15
int strncmp(const char *s1, const char *s2, size_t n);
int main (void)
{
char lname[CLASS_SIZE][NAME_LEN];
char fname[CLASS_SIZE][NAME_LEN];
int age[CLASS_SIZE];
char *temp;
for(int i=1; i<=CLASS_SIZE; i++)
{
printf("Enter first name, last name and age : ");
scanf("%s %s %d", fname[i], lname[i], &age[i]);
}
for (int x=0; x<CLASS_SIZE; x++)
{
for (int y=1; y<NAME_LEN; y++)
{
if (strncmp(lname[y-1], lname[y],NAME_LEN)>0)
{
temp = lname[y];
lname[y] = lname[y-1];
lname[y-1] = temp;
}
}
}
for(int a=1; a<=CLASS_SIZE; a++)
printf("%s ", lname[a] );
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