Question

Write a complete C program. Define a structure type element_t to represent one element from the...

Write a complete C program.

Define a structure type element_t to represent one element from the periodictable of elements. Components should include the atomic number (aninteger); the name, chemical symbol, and class (strings); a numeric field forthe atomic weight; and a seven-element array of integers for the number ofelectrons in each shell. The following are the components of an element_t

structure for sodium.11 Sodium Na alkali_metal 22.9898 2 8 1 0 0 0 0

Have the user enter the data for one element and then display that data on the screen.

-----------------------------------------example---------------------------------------------------------------

#include <stdio.h>
#include <math.h>

struct point
{
        float x;
        float y;
};

typedef struct point POINT;

POINT input_POINT();
void print_POINT(POINT);
POINT calc_midPOINT(POINT,POINT);
float calc_distance(POINT,POINT);
float calc_slope(POINT,POINT);
void determine_quadrant(POINT);

int main()
{
        POINT a,b,mid;
        float distance,slope;
        
        printf("This program allows you to enter\n");
        printf("two Cartesian coordinate points\n");
        printf("and will then analyze them!\n\n");
        
        printf("It is time to enter your first point\n");
        a=input_POINT();
        printf("\n");
        
        printf("It is time to enter your second point\n");
        b=input_POINT();
        
        printf("\n\n");
        printf("First point entered:");
        print_POINT(a);
        printf("\n");
        determine_quadrant(a);
        printf("\n");
        printf("Second point entered:");
        print_POINT(b);
        printf("\n");
        determine_quadrant(b);
        printf("\n");
        
        mid = calc_midPOINT(a,b);
        
        printf("Midpoint:");
        print_POINT(mid);
        printf("\n");
        
        distance = calc_distance(a,b);  
        printf("The distance between the points is: %8.2f\n",distance);
        
        printf("\n");
        
        if(a.x == b.x)
                printf("The slope is undefined\n");
        else
                {
                        slope = calc_slope(a,b);
                        printf("The slope is: %8.2f\n",slope);
                }
                
        
        return 0;
}

void determine_quadrant(POINT p)
{
        if(p.x==0 && p.y==0)
                printf("Point is on the origin\n");
        else if (p.x > 0 && p.y >0)
                printf("Point is in Quadrant I\n");
        else if (p.x < 0 && p.y >0)
                printf("Point is in Quadrant II\n");
        else if (p.x<0 && p.y <0)
                printf("Point is in Quadrant III\n");
        else if (p.x>0 && p.y < 0)
                printf("Point is in Quadrant IV\n");
        else if(p.y==0 && p.x!=0)
                printf("Point is on X-axis\n");
        else
                printf("Point is on Y-axis\n");
        
}

float calc_slope(POINT a, POINT b)
{
        float temp;
        
        temp = (b.y - a.y)/(b.x - a.x);
        
        return temp;
        
}

float calc_distance(POINT a, POINT b)
{
        float temp;
        
        temp = sqrt(pow(b.x - a.x,2) + pow(b.y - a.y,2));
        
        return temp;    
}

POINT calc_midPOINT(POINT a, POINT b)
{
        POINT temp;
        
        temp.x = (a.x + b.x)/2;
        temp.y = (a.y + b.y)/2;
        
        return temp;
}

void print_POINT(POINT p)
{
        printf("(%6.2f,%6.2f)\n",p.x,p.y);
}


POINT input_POINT()
{
        POINT temp;
        
        printf("Enter the x coordinate of your point\n");
        scanf("%f",&temp.x);
        printf("Enter the y coordinate of your point\n");
        scanf("%f",&temp.y);
        
        return temp;
}

-----------------------------------------example---------------------------------------------------------------

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the C program for the above task:

#include <stdio.h>

#include <string.h>

//declaring element_t struct

struct element_t {

   int atomicNum;

   char name[20];

   char symbol[5];

   char class[20];

   float atomicWt;

   int electronConfg[7];

};

int main() {

   struct element_t element; //element variable of type element_t

   /* take input for user */

   printf("Enter atomic number: ");

   scanf("%d", &element.atomicNum);

   printf("Enter element's name: ");

   scanf("%s", element.name);

   printf("Enter element's symbol: ");

   scanf("%s", element.symbol);

   printf("Enter element's class: ");

   scanf("%s", element.class);

   printf("Enter atomic weight: ");

   scanf("%f", &element.atomicWt);

   printf("Enter element's electronic confg: ");

   int i;

   for (i = 0; i < 7; ++i) {

       scanf("%d", &element.electronConfg[i]);

   }

   printf("\n");

   /* print data to screen */

   printf("atomic number: %d\n", element.atomicNum);

   printf("element's name: %s\n", element.name);

   printf("element's symbol: %s\n", element.symbol);

   printf("element's class: %s\n", element.class);

   printf("atomic weight: %f\n", element.atomicWt);

   printf("element's electronic confg: ");

   for (i = 0; i < 7; ++i) {

       printf("%d ", element.electronConfg[i]);

   }

   printf("\n\n");

}


Sample IO:

1: bash PROBLEMS TERMINAL [unseen@pc]07:51 am_$ ~/prog/C gcc main.c -o main [unseen@pc]07:51 am_$ ~/prog/C -> ./main Enter at

Add a comment
Know the answer?
Add Answer to:
Write a complete C program. Define a structure type element_t to represent one element from the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Why i having this error using opengl C++ here part of code #include "glaux.h" #include "glut.h"...

    Why i having this error using opengl C++ here part of code #include "glaux.h" #include "glut.h" #include <stdio.h> #include <stdlib.h> #include <conio.h> #define _USE_MATH_DEFINES #include <math.h> #include <time.h> some coder here and etc bool isGood(Tpos a) { DataToCp(); int k=0,i,j,lt; Tpos temp; cp[a.y][a.x]='x'; if ((step(a.y,a.x)>3)||(step(a.y+1,a.x)>3)||(step(a.y-1,a.x)>3)||(step(a.y,a.x+1)>3)||(step(a.y,a.x-1)>3)) return false; for(j=1;j<=m;j++) for(i=1;i<=m;i++) if (cp[j][i]=='.') { if (k>0) return false; fill(j,i,&temp,&lt); k++; } return true; } void genMap() { int i,j; map.x=m+2; map.z=m+2; printf("Loading...\n"); srand( (unsigned)time( NULL ) ); for (j=0;j<map.z;j++) for (i=0;i<map.x;i++) {...

  • C programming - This is what I have so far but it is not working correctly....

    C programming - This is what I have so far but it is not working correctly. It must contain the function and it also needs a provision to write output to a file. Can anyone help? #include <stdio.h> I #include <math.h int main (void) int V float Rint, RLE0, 0; printf New power supply voltage scanf ("td", &V) printf Enter a valid Internal Resistance (Rint) range between 200 and 5k ohms: scanf ("tf", Rint if (V> 1 && VK 15)...

  • C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string usi...

    C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...

  • Need help in C (a) Write a C program to read in a line of text...

    Need help in C (a) Write a C program to read in a line of text and count the occurrence of each English alphabet. The lowercase version of a letter is considered the same as the uppercase. To make viewing easy, the frequencies should be presented using a bar chart as follows. You can assume that the input contains only spaces, lowercase letters, uppercase letters and the newline character (i.e. the Enter key). Enter a line of text: Letter ZZz...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • Using C, I need help debugging this program. I have a few error messages that I'm...

    Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...

  • Need help with shuffle function and give 8 cards to user and computer from shuffle deck?...

    Need help with shuffle function and give 8 cards to user and computer from shuffle deck? #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> typedef struct card_s{     char suit;     int face;     struct card_s *listp; } card; void card_create(card* thisNode, char cardSuit, int cardFace, card* nextLoc) {     thisNode->suit = cardSuit;     thisNode->face = cardFace;     thisNode->listp = nextLoc;     return; } void card_insertAfter(card* thisNode, card* newNode) {     card* tmpNext = NULL;    ...

  • Write a complete C program that inputs a paragraph of text and prints out each unique...

    Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...

  • help KKKL1164 4. The C program presented below has some syntax and logic errors. Analyse it...

    help KKKL1164 4. The C program presented below has some syntax and logic errors. Analyse it and highlight the errors, explaining how the errors can be corrected. This program attempts to solve a quadratic equation. #include <stdio.h> #include <math.h> int Main() const int a, b, Ci double doro, disc printf ("Lets find the root (s) of a printf ("ax 2 bx c. \n"); printf ("Please enter the coefficient a: scanf ("d", &c); printf ("Please enter the coefficient b: "); scanf...

  • What to do Write a C program that computes Pi with the approximation algorithm that I...

    What to do Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT