Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What we want to do in this assignment is we want to break our main file into thr

ID: 669480 • Letter: W

Question

What we want to do in this assignment is we want to break our main file into three files: interface, client, and implementation. What you will need to decide the following:

There is no functions in the main file we have, only the main method, how can you break the main method into smaller ones, each specific for a certain task? What name are you going to use for these methods? what would be the input for the methods?

Based on how you are going to break the main into smaller methods, create your interface to include the method prototype

Remaining is the client. Connect your methods and call them in the correct order to obtain the same behavior we had before for the main.c file.

Things to consider while programming:

No global variables are allowed

For the method parameters, chose only the ones that need to be sent. If a parameter only needed by a single method, then it has to be a local variable to this method.

IM USING SFML IN C. HOW TO BREAK THIS MAIN.C INTO A HEADER FILE .h AND IMPLEMENTATION FILE .c.

THIS IS MY CODE:

//include directive

#include

#include

#include

#include

int main(void)

{

  

// change the size of the window

sfVideoMode mode = {200, 300, 32};

sfRenderWindow* window;

sfCircleShape* circle;

sfEvent event;

  

// allocates memory

window = sfRenderWindow_create(mode, "Olti Asllanaj", sfResize | sfClose, NULL);

if (!window)

return 1;

  

//create a circle to display

circle = sfCircleShape_create();

if(!circle)

return 1;

//changes the radius of the circle

sfCircleShape_setRadius(circle, 100);

//changes the color of the cicrcle

sfCircleShape_setFillColor(circle, sfTransparent);

  

// checks if the window is open

while (sfRenderWindow_isOpen(window))

{

  

while (sfRenderWindow_pollEvent(window, &event))

{

// close window: exit

if (event.type == sfEvtClosed)

sfRenderWindow_close(window);

}

  

// Clear screen and change the color of the window

sfRenderWindow_clear(window, sfBlack);

sfRenderWindow_drawCircleShape(window, circle, NULL);

  

//dispaly window

sfRenderWindow_display(window);

}

//destroy the window and the circle

sfCircleShape_destroy(circle);

sfRenderWindow_destroy(window);

  

return 0;

}

Explanation / Answer

Main Program:

//include directive
#include "swindow.h"
#include <iostream>

using namespace std;

int main()
{
  
sfRenderWindow RW;
sfCircleShape CS;
sfRenderWindow* window; // Pointer of class type
sfRenderWindow* window;
sfCircleShape* circle;
sfEvent event;
// change the size of the window
sfVideoMode VM;
VM.mode= {200, 300, 32};
// allocates memory
window = RW.sfRenderWindow_create(mode, "Olti Asllanaj", sfResize | sfClose, NULL);
if (!window)
return 0;
  
//create a circle to display
circle = CS.sfCircleShape_create();
if(!circle)
return 0;
//changes the radius of the circle
CS.sfCircleShape_setRadius(circle, 100);
//changes the color of the cicrcle
CS.sfCircleShape_setFillColor(circle, sfTransparent);
  
// checks if the window is open
while (RW.sfRenderWindow_isOpen(window))
{
  
while (RW.sfRenderWindow_pollEvent(window, &event))
{
// close window: exit
if (event.type == sfEvtClosed)
RW.sfRenderWindow_close(window);
}
  
// Clear screen and change the color of the window
RW.sfRenderWindow_clear(window, sfBlack);
VM.sfRenderWindow_drawCircleShape(window, circle, NULL);
  
//dispaly window
RW.sfRenderWindow_display(window);
}
//destroy the window and the circle
CS.sfCircleShape_destroy(circle);
RW.sfRenderWindow_destroy(window);
  
return 0;
}

//swindow.cpp

#include "swindow.h"
using namespace std;
// put datatype for NULL
sfRenderWindow* sfRenderWindow::sfRenderWindow_create(int mode, string s, bool status, NULL){
   //definition here
}
bool sfRenderWindow::sfRenderWindow_isOpen(sfRenderWindow* window){
   //definition here
}
void sfRenderWindow::sfRenderWindow_close(sfRenderWindow* window){
   //definition here
}
void sfRenderWindow::sfRenderWindow_clear(sfRenderWindow* window, Color){
   //definition here
}
//dispaly window
void sfRenderWindow::sfRenderWindow_display(sfRenderWindow* window){
   //definition here
}
void sfRenderWindow::sfRenderWindow_destroy(sfRenderWindow* window){
   //definition here
}
bool sfRenderWindow::sfRenderWindow_pollEvent(sfRenderWindow*,sfEvent &event){
   //definition here
}
void sfVideoMode::sfRenderWindow_drawCircleShape(sfRenderWindow*, sfCircleShape, NULL){
   //definition here
}  
void sfCircleShape::sfCircleShape_destroy(sfCircleShape* circle){
   //definition here
}
void sfCircleShape::sfCircleShape_setRadius(sfCircleShape*, int){
   //definition here
}
sfCircleShape* sfCircleShape::sfCircleShape_create(void){
   //definition here
}
void sfCircleShape::sfCircleShape_setFillColor(sfCircleShape*, Color){
   //definition here
}

//swindow.h

#include <iostream>
using namespace std;

class sfRenderWindow
{
   //members here
public:
// change the parameters data typpe according to your definition of sfRenderWindow
// put datatype instead of NULL
sfRenderWindow* sfRenderWindow_create(int mode, string s, bool status, NULL);
bool sfRenderWindow_isOpen(sfRenderWindow* window);
void sfRenderWindow_close(sfRenderWindow* window);
void sfRenderWindow_clear(sfRenderWindow* window, Color);
//dispaly window
void sfRenderWindow_display(sfRenderWindow* window);
void sfRenderWindow_destroy(sfRenderWindow* window);
bool sfRenderWindow_pollEvent(sfRenderWindow*,sfEvent &event);  
};

class sfVideoMode
{
   public:
   int mode[3];
// here change the data type for NULL
void sfRenderWindow_drawCircleShape(sfRenderWindow*, sfCircleShape, NULL);   
};

class sfCircleShape
{
   //members here
   public:
   void sfCircleShape_destroy(sfCircleShape* circle);
   void sfCircleShape_setRadius(sfCircleShape*, int);
   sfCircleShape* sfCircleShape_create(void);
   void sfCircleShape_setFillColor(sfCircleShape*, Color);
};

class sfEvent
{
   //members here
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote