A struct that implements the idea of a Circle struct Circle

A struct that implements the idea of a Circle struct Circle : CustomstringConvertible var radius: Double in it (radius: Double ) { self.radius = radius //return area of circle func area (O) ->Double returnDouble .pi radius * radius I/return circumference of circle func circumference (O) ->Double return 2 * Double-pi radius 1/return difference in area of this circle and a given circle func differenceInArea (. C: Circle ) - > Double return area () - C. area (O) //a textual representation of the circle var description: String return \"radius: I (radius) area : (area ()) circumference : I (circumference (O) \" I/Sample Test Code let c1 = Circle (radius: 5) let c2 = Circle (radius: 10) print (\"Circle 1: A (Cl ) \") print (\"Circle 2: A (C2 ) \") print (\'Area difference between the two circles: \\(ci.differenceInArea (c2))\") print () var circles = [Circle] () circles.append (cl) circles.append (C2) circles.append (Circle (radius: 15)) for C in circles {print (c) } I/Test Code Results Circle 1 : radius: 5.0 area: 78.5398163397448 circumference: 31. 4159265358979 Circle 2: radius : 10.0 area: 314.1592 65358979 circumference : 62.8318530717959 Area difference between the two circles: -235.619449019234 radius : 5.0 area: 78.5398163397448 circumference : 31.4159265353 979 radius : 10.0 area : 314.1592 65358979 circumference: 62.8318530717959 radius: 15.0 area: 706.858347057703 circumference: 94.2477796076938 Program ended with exit code: 0

Solution

#include <stdio.h>

main ()

{

    union id {

      char name[40];

      int number;

    };

    struct {

      int salary;

      union id description;

    } student,faculty;

    printf(\"%d\ \", sizeof(union id));

    student.description.name =\"Sam\";

    printf(\"%s %d\ \",

student.description.name,student.description.number);

    student.description.number = 12;

    printf(\"%s %d\ \",

student.description.name,student.description.number);

}


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site