Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Центр помощи > [C] Структуры и динамическое выделение памяти


Автор: custard 22.12.2006, 10:49
нужно написать код используя эти  structures

надо писать с  Dynamic Memory Allocation (malloc) 

Код

struct polynomial {
    int degree;
    float *coeff;
};


//держит координаты X и Y
struct point {
    float x,y;
}


//Линия на Х- Y связывает P1 c P2 и длину 
struct line_segment {
    struct point P1,P2;
struct point mid_point;
    float length;
}

//Круг с центром и радиусом,держит площадь круга
struct circle {
    struct point center;
    float radius, area;
}


Юзер входит это

Please enter your choice:
1. Polynomial addition
2. Polynomial multiplication
3. Intersection of lines
4. The nearest point of a circle to the mid-point of a line
5. The point in the middle of the mid-points of two lines
6. Length of a line
7. Area of a circle
8. Exit


например выбрал 1-ый пункт сделал полиномиал адишн потом спрашиваешь что шас хочешь сделать пока юзер не напишеT  Exit-t.e 8

функции для использования
•    inputPolynomial: Inputs a polynomial from the user
o    Ask the degree of the polynomial, allocate the coeff member accordingly, read the coefficients one by one and make the resulting polynomial visible in the scope that calls this function (either using call-by-value or call-by reference)
•    inputPoint: Inputs a point from the user
o    Read the coordinates of a point and return the resulting point to the caller scope (again either using call-by-value or call-by reference)
•    inputCircle: Inputs a circle from the user
o    Read the parameters of a circle and return the resulting circle to the caller
•    inputLine: Inputs a line segment from the user
o    Read the two points of a line and return the resulting line to the caller

оутпут функции

•    outputPolynomial: Prints a given polynomial in an orderly way
•    outputPoint: Outputs the coordinates of a given point imn an orderly way.
•    outputArea: Outputs the area of a given circle in an orderly way
•    outputLength: Outputs the length of a given line segment in an orderly way



The operational functioms you must implement are:

•    polyAdd            (Operation 1)
•    polyMult            (Operation 2)
•    lineIntersect        (Operation 3)
•    pointNearest        (Operation 4)
•    pointMiddle        (Operation 5)
•    length            (Operation 6)
•    area                (Operation 7)


The basic data types to be used in the project are defined as follows:

//Keeps the coefficients of a polynomial of a particular degree
//coeff[0] is supposed to keep the constant term (of degree 0)
//coeff[1] is supposed to keep the term of degree 1 (x^1)
//coeff[2] is supposed to keep the term of degree 2 (x^2)
//coeff[3] is supposed to keep the term of degree 3 (x^3)

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)