In C Programming, Write a program that can finish the following tasks: A. Create
ID: 3824614 • Letter: I
Question
In C Programming, Write a program that can finish the following tasks:
A. Create a structure, called creditcard that contains three members:
credit_card_number (integer data type), authorization_number (integer data type) and amount_to_charge (float data type):
B. Create an array called records, which contains 50 creditcard structures.
C. Using three lines of code, initialize the data for records[25] to: credit_card_number = 4111111, authorization_number=56222 and amount_to_charge = 29.95.
D. Create a pointer to creditcard and call it cardPtr. Initialize cardPtr to point to the zeroeth element of the records array.
E. Using cardPtr defined above, initialize the data for records[0] to: credit_card_number=599121, authorization_number = 89333 and amount_to_charge = 49.95.
F. Using cardPtr, print out all data contained in records[25].
Explanation / Answer
Hi, Please find my implementation.
#include <stdio.h>
//A
struct creditcard{
int credit_card_number;
int authorization_number;
float amount_to_charge;
};
int main(){
//B
struct creditcard records[50];
//c
records[25].credit_card_number = 4111111;
records[25].authorization_number=56222;
records[25].amount_to_charge = 29.95;
//d
struct creditcard *cardPtr = &records[0];
//e
cardPtr->records[0].credit_card_number=599121;
cardPtr->records[0].authorization_number = 89333;
cardPtr->records[0].amount_to_charge = 49.95;
//f
printf("%d ", cardPtr->records[25].credit_card_number);
printf("%d ", cardPtr->records[25].authorization_number);
printf("%d ", cardPtr->records[25].amount_to_charge);
}