Please help me with this program and do use preferences on data that is iputted for family
Please don't use cout or cin statements, Thank you so much :)
![Write a C program that assigns family information to structures: struct family { char name [50]; /* persons name */ char str](http://img.homeworklib.com/questions/1df37160-b0c9-11ea-8575-7b345cbdc63e.png?x-oss-process=image/resize,w_560)
Please don't use cout or cin statements, Thank you so much :)
Hi,
Program:
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
struct family
{
char name[50];
char street[50];
char csz[50];
char relation[50];
char birthday[50];
};
int main()
{
int n = 5; //considering there are five(5) family members
//if you have more then chnage the value of n
struct family people[n];
FILE *fp;
char str[50];
/* opening file for reading */
fp = fopen("family.txt", "r");
if (fp == NULL)
{
perror("Error opening file");
return (-1);
}
int k = 1, j = 0;
while (fgets(str, 50, fp) != NULL)
{
if (str[strlen(str) - 1] == '\n')
str[strlen(str) - 1] = '\0';
if (k == 1)
strcpy(people[j].name, str);
else if (k == 2)
strcpy(people[j].street, str);
else if (k == 3)
strcpy(people[j].csz, str);
else if (k == 4)
strcpy(people[j].relation, str);
else if (k == 5)
strcpy(people[j].birthday, str);
if (k % 5 == 0)
{
k = 0;
j++;
}
k++;
}
fclose(fp);
fp = fopen("familyout.txt", "w");
for (int i = 0; i < n; i++)
{
char s[100];
strcpy(s, "Relation: ");
strcat(s, people[i].relation);
// Returns first token
char *token = strtok(people[i].birthday, "-");
int year, month, day, x = 0;
char d[50], y[50];
// Keep printing tokens while one of the
// delimiters present in str[].
while (token != NULL)
{
// printf("%s\n", token);
if (x == 0)
month = atoi(token);
else if (x == 1)
{
day = atoi(token);
strcpy(d, token);
}
else
{
year = atoi(token);
strcpy(y, token);
}
token = strtok(NULL, "-");
x++;
}
char m[30];
if (month == 1)
strcpy(m, "Jan ");
else if (month == 2)
strcpy(m, "Feb ");
else if (month == 3)
strcpy(m, "Mar ");
else if (month == 4)
strcpy(m, "Apr ");
else if (month == 5)
strcpy(m, "May ");
else if (month == 6)
strcpy(m, "Jun ");
else if (month == 7)
strcpy(m, "Jul ");
else if (month == 8)
strcpy(m, "Aug ");
else if (month == 9)
strcpy(m, "Sep ");
else if (month == 10)
strcpy(m, "Oct ");
else if (month == 11)
strcpy(m, "Nov ");
else if (month == 12)
strcpy(m, "Dec ");
strcat(m, d);
strcat(m, ", ");
strcat(m, y);
char s1[100];
strcpy(s1, "Age: ");
strcat(s1, people[i].relation);
time_t t = time(NULL);
struct tm tm = *localtime(&t);
int cy = tm.tm_year + 1900;
int cm = tm.tm_mon + 1;
int cd = tm.tm_mday;
int month1[] = {31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31};
// if birth date is greater then current birth
// month then do not count this month and add 30
// to the date so as to subtract the date and
// get the remaining days
if (day > cd)
{
cd = cd + month1[month - 1];
cm = cm - 1;
}
// if birth month exceeds current month, then do
// not count this year and add 12 to the month so
// that we can subtract and find out the difference
if (month > cm)
{
cy = cy - 1;
cm = cm + 12;
}
int calculated_year = cy - year;
printf("%s %25s\n", people[i].name, s);
printf("%s %25s\n", people[i].street, m);
printf("%s Age:%d\n", people[i].csz, calculated_year);
fprintf(fp, "%s %25s\n", people[i].name, s);
fprintf(fp, "%s %25s\n", people[i].street, m);
fprintf(fp, "%s Age:%d\n", people[i].csz, calculated_year);
}
return 0;
}

![60 fp fopen( familyout . txt, w ) ; 61 62 63 for (int i = 0; i < n; 1++) { 64 65 char s[100]; strcpy(s, Relation : ); s](http://img.homeworklib.com/questions/d22cac20-b0c9-11ea-8f0f-a3639c403f22.png?x-oss-process=image/resize,w_560)

Output Screenshot:


family.txt:
Joe B. Redfield
6220 Culbera
San Antonio, TX 78228
Self
10-03-1956
Neil M. Redfield
6220 Culbera
San Antonio, TX 78228
Wife
12-31-1960
Sam K. Redfield
6220 Culbera
San Antonio, TX 78228
Son
06-13-1982
Amy J. Redfield
6220 Culbera
San Antonio, TX 78228
daughter
04-13-1984
John M. Redfield
6220 Culbera
San Antonio, TX 78228
Son
1-03-1987
familyout.txt:
Joe B. Redfield Relation: Self
6220 Culbera Oct 03, 1956
San Antonio, TX 78228 Age:63
Neil M. Redfield Relation: Wife
6220 Culbera Dec 31, 1960
San Antonio, TX 78228 Age:58
Sam K. Redfield Relation: Son
6220 Culbera Jun 13, 1982
San Antonio, TX 78228 Age:37
Amy J. Redfield Relation: daughter
6220 Culbera Apr 13, 1984
San Antonio, TX 78228 Age:35
John M. Redfield Relation: Son
6220 Culbera Jan 03, 1987
San Antonio, TX 78228 Age:32
Please help me with this program and do use preferences on data that is iputted for...
Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...
Write a C++ program that uses a structure to store the following inventory information in a file: ⦁ Item description, Quantity on hand, Wholesale cost, Retail cost, and Date added to inventory. ⦁ Use a char array for item description and date. ⦁ The program should have a menu that allows the user to perform the following tasks: i. Add a new record at the end of the file. ii. Display any record in the file. iii. Change any record...
== Programming Assignment == For this assignment you will write a program that reads in the family data for the Martian colonies and stores that data in an accessible database. This database allows for a user to look up a family and its immediate friends. The program should store the data in a hashtable to ensure quick access time. The objective of this assignment is to learn how to implement and use a hashtable. Since this is the objective, you...
-can you change the program that I attached to make 3 file
songmain.cpp , song.cpp , and song.h
-I attached my program and the example out put.
-Must use Cstring not string
-Use strcpy
- use strcpy when you use Cstring: instead of this->name=name
.... use strcpy ( this->name, name)
- the readdata, printalltasks, printtasksindaterange,
complitetasks, addtasks must be in the Taskmain.cpp
- I also attached some requirements below as a picture
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>...
Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...
Write a program that supports the three phases (setup, voting and result-tallying) which sets up and executes a voting procedure as described above. In more details: You can start with the given skeleton (lab6_skeleton.cpp). There are two structures: Participant structure, which has the following members: id -- an integer variable storing a unique id of the participant (either a candidate or a voter). name -- a Cstring for storing the name of the participant.. hasVoted -- a boolean variable for...
This program has an array of floating point numbers as a private data member of a class. The data file contains floating point temperatures which are read by a member function of the class and stored in the array. Exercise 1: Why does the member function printList have a const after its name but getList does not? Exercise 2: Fill in the code so that the program reads in the data values from the temperature file and prints them to...
Please, please help with C program.
This is a longer program, so take your time. But please make
sure it meets all the requirements and runs.
Here is the assignment:
I appreciate any help given.
Cannot use goto or system(3) function unless directed to.
In this exercise you are to create a database of dogs in a file, using open, close(), read, write(), and Iseek(). Do NOT use the standard library fopen() ... calls! Be sure to follow the directions!...
Based on this program modify the source code so that it will able to save the student record into a database txt and able to display and modify from a database txt as well. you will also need to able to modify the code so it will accept name such as "john kenny " and the progrom should also ask for the student id number. #include<iostream> #include<stdlib.h> using namespace std; struct st { int roll; char name[50]; char grade; struct...