This commit is contained in:
superdimensional 2021-01-29 16:05:36 -05:00 committed by GitHub
parent 891f69ac17
commit a3d0693e69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 374 additions and 0 deletions

64
functions.h Normal file
View file

@ -0,0 +1,64 @@
#include <math.h>
#include <stdio.h>
double exponent( double par){
double raisedNum;
raisedNum = par * par;
return raisedNum;
};
double hypotenuse(double par, double par2){
double sideC;
sideC = sqrt( exponent(par) + exponent(par2) );
return sideC;
};
void quadratic(double numA, double numB, double numC, double *awn1ptr, double *awn2ptr){
double awn1 = (-numB) + sqrt( exponent(numB) - 4 * numA * numC);
double awn1F = awn1 / (2 * numA);
double awn2 = (-numB) - sqrt( exponent(numB) - 4 * numA * numC);
double awn2F = awn2 / (2 * numA);
*awn1ptr = awn1F;
*awn2ptr = awn2F;
};
double areaOfCircle(double radius){
double area;
area = acos(-1) * exponent(radius);
return area;
}
int buildMatrix(int numRows, int numColumns)
{
int matrix[numRows][numColumns];
printf("Enter elements in matrix of size %dx%d \n", numRows, numColumns);
for(int i = 0; i < numRows; i++)
{
for(int j = 0; j < numColumns; j++)
{
scanf("%d", &matrix[i][j]);
}
}
printf("\nElements in matrix are: \n");
for(int i = 0; i < numRows; i++)
{
for(int j = 0; j < numColumns; j++)
{
printf("%d ", matrix[i][j]);
}
printf("\n");
}
return 0;
}

215
index.c Normal file
View file

@ -0,0 +1,215 @@
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdbool.h>
//import C libraries
//gcc -Wall -Werror -pedantic -std=c11 index.c `pkg-config --cflags --libs gtk+-3.0`
//using GTK+ 3.0
/* Function called when the user clicks the show button. */
void on_show_button_1_clicked(GtkWidget *show_button1, GtkWidget *hello_display)
{
printf("1 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>1</span>");
}
void on_show_button_2_clicked(GtkWidget *show_button2, GtkWidget *hello_display)
{
printf("2 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>2</span>");
}
void on_show_button_3_clicked(GtkWidget *show_button3, GtkWidget *hello_display)
{
printf("3 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>3</span>");
}
void on_show_button_4_clicked(GtkWidget *show_button4, GtkWidget *hello_display)
{
printf("4 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>4</span>");
}void on_show_button_5_clicked(GtkWidget *show_button5, GtkWidget *hello_display)
{
printf("5 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>5</span>");
}
void on_show_button_6_clicked(GtkWidget *show_button6, GtkWidget *hello_display)
{
printf("6 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>6</span>");
}void on_show_button_7_clicked(GtkWidget *show_button7, GtkWidget *hello_display)
{
printf("7 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>7</span>");
}
void on_show_button_8_clicked(GtkWidget *show_button8, GtkWidget *hello_display)
{
printf("8 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>8</span>");
}void on_show_button_9_clicked(GtkWidget *show_button9, GtkWidget *hello_display)
{
printf("9 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>9</span>");
}
void on_show_button_0_clicked(GtkWidget *show_button0, GtkWidget *hello_display)
{
printf("0 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>0</span>");
}
/* Function called when the user clicks the clear button */
void on_clear_button_clicked(GtkWidget *clear_button, GtkWidget *hello_display)
{
/* Display an empty message (clear the greeting). */
gtk_label_set_text(GTK_LABEL(hello_display), "");
}
/* Build the application window with all its components */
void build_window(void)
{
/* Declares the list of variables. Each one will represent one
* graphical element (called a widget). */
GtkWidget *hello_window, *layout;
GtkWidget *hello_display, *show_button1, *show_button2, *show_button3, *show_button4, *show_button5, *show_button6, *show_button7, *show_button8, *show_button9, *show_button0, *clear_button;
/* Creates the text box (label) and two buttons. */
hello_display = gtk_label_new(NULL);
show_button1 = gtk_button_new();
show_button2 = gtk_button_new();
show_button3 = gtk_button_new();
show_button4 = gtk_button_new();
show_button5 = gtk_button_new();
show_button6 = gtk_button_new();
show_button7 = gtk_button_new();
show_button8 = gtk_button_new();
show_button9 = gtk_button_new();
show_button0 = gtk_button_new();
gtk_button_set_label(GTK_BUTTON(show_button1), "1");
gtk_button_set_label(GTK_BUTTON(show_button2), "2");
gtk_button_set_label(GTK_BUTTON(show_button3), "3");
gtk_button_set_label(GTK_BUTTON(show_button4), "4");
gtk_button_set_label(GTK_BUTTON(show_button5), "5");
gtk_button_set_label(GTK_BUTTON(show_button6), "6");
gtk_button_set_label(GTK_BUTTON(show_button7), "7");
gtk_button_set_label(GTK_BUTTON(show_button8), "8");
gtk_button_set_label(GTK_BUTTON(show_button9), "9");
gtk_button_set_label(GTK_BUTTON(show_button0), "0");
clear_button = gtk_button_new();
gtk_button_set_label(GTK_BUTTON(clear_button), "Clear");
/* Connects the "clicked" input events happening at the buttons to
* their callback functions (on_show_button_clicked() and
* on_clear_button_clicked()). */
g_signal_connect(show_button1, "clicked",
G_CALLBACK(on_show_button_1_clicked),
hello_display);
g_signal_connect(show_button2, "clicked",
G_CALLBACK(on_show_button_2_clicked),
hello_display);
g_signal_connect(show_button3, "clicked",
G_CALLBACK(on_show_button_3_clicked),
hello_display);
g_signal_connect(show_button4, "clicked",
G_CALLBACK(on_show_button_4_clicked),
hello_display);
g_signal_connect(show_button5, "clicked",
G_CALLBACK(on_show_button_5_clicked),
hello_display);
g_signal_connect(show_button6, "clicked",
G_CALLBACK(on_show_button_6_clicked),
hello_display);
g_signal_connect(show_button7, "clicked",
G_CALLBACK(on_show_button_7_clicked),
hello_display);
g_signal_connect(show_button8, "clicked",
G_CALLBACK(on_show_button_8_clicked),
hello_display);
g_signal_connect(show_button9, "clicked",
G_CALLBACK(on_show_button_9_clicked),
hello_display);
g_signal_connect(show_button0, "clicked",
G_CALLBACK(on_show_button_0_clicked),
hello_display);
g_signal_connect(clear_button, "clicked",
G_CALLBACK(on_clear_button_clicked),
hello_display);
/* Create a layout element to visually organize widgets. */
layout = gtk_grid_new();
gtk_grid_attach(GTK_GRID(layout), hello_display, 0, 0, 3, 1);
gtk_grid_attach(GTK_GRID(layout), show_button1, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button2, 1, 1, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button3, 2, 1, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button4, 0, 2, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button5, 1, 2, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button6, 2, 2, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button7, 0, 3, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button8, 1, 3, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button9, 2, 3, 1, 1);
gtk_grid_attach(GTK_GRID(layout), show_button0, 0, 4, 1, 1);
gtk_grid_attach(GTK_GRID(layout), clear_button, 1, 4, 2, 1);
gtk_grid_set_row_homogeneous(GTK_GRID(layout), TRUE);
gtk_grid_set_column_homogeneous(GTK_GRID(layout), TRUE);
gtk_grid_set_row_spacing(GTK_GRID(layout), 8);
gtk_grid_set_column_spacing(GTK_GRID(layout), 32);
gtk_widget_set_margin_start(layout, 20);
gtk_widget_set_margin_end(layout, 20);
gtk_widget_set_margin_top(layout, 20);
gtk_widget_set_margin_bottom(layout, 20);
/* Finally, create the main window and insert the whole layout
* inside. */
hello_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(hello_window), "Graphical Hello");
gtk_window_set_default_size(GTK_WINDOW(hello_window), 400, 300);
gtk_container_add(GTK_CONTAINER(hello_window), layout);
gtk_widget_show_all(hello_window);
/* Connects the "destroy" event, generated when closing the window
* to the gtk_main_quit() function, which asks to stop the event
* loop, so that the program can finish. */
g_signal_connect(hello_window, "destroy", G_CALLBACK(gtk_main_quit),
NULL);
}
/* main() function called when program starts. */
int main(int argc, char *argv[]) {
/* Call the gtk initialization function */
gtk_init(&argc, &argv);
/* Call our function to build the complete program window. */
build_window();
/* Enter Gtk+ main event loop (sleeps waiting for input events,
* like mouse or keyboard input, then wakes up calling the registered
* event callbacks and goes back to sleep until exit is requested). */
gtk_main();
/* After the main loop quits just return zero to the operating
* system. */
return 0;
}

95
main.c Normal file
View file

@ -0,0 +1,95 @@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "functions.h"
int main (){
system("clear");
printf("Welcome to Calculator Collection™.\nPlease select which calculator you would like to use.");
printf("\n\n 1. Hypotenuse calculator");
printf("\n 2. Quadratic formula calculator");
printf("\n 3. Area of a circle");
printf("\n 4. Matrix");
printf("\n\n Enter your choice here:_____");
printf("\033[D");
printf("\033[D");
printf("\033[D");
int userInput;
scanf("%i", &userInput);
switch(userInput){
case 1:
system("clear");
printf("\n ~~ Hypotenuse calculator ~~");
printf("\n\n /|\n");
printf(" / |\n");
printf(" c / |\n");
printf(" / | a\n");
printf(" / |\n");
printf(" /_____|\n\n");
printf(" b\n");
printf("\nPlease type the length of the triangle below:\n");
double sideA;
scanf("%lf", &sideA);
printf("\nPlease type the width of the triangle:\n");
double sideB;
scanf("%lf", &sideB);
printf("The Hypotnuse is equal to %f.\n", hypotenuse(sideA, sideB));
break;
case 2:
system("clear");
printf("\n ~~ Quadratic formula calculator ~~\n\n");
printf("Please enter the value for \"a\":\n");
double numA;
scanf("%lf", &numA);
printf("Please enter the value for \"b\":\n");
double numB;
scanf("%lf", &numB);
printf("Please enter the value for \"c\":\n");
double numC;
scanf("%lf", &numC);
double awn1ptr, awn2ptr;
quadratic(numA, numB, numC, &awn1ptr, &awn2ptr);
printf("The zeros are: %f and %f!\n", awn1ptr, awn2ptr);
break;
case 3:
system("clear");
printf("\n ~~ Area of a circle calculator ~~\n\n");
printf(" o o\n o o\n o o\n o o\n o o\n o o\n");
printf("\n enter a radius:\n");
double radius;
scanf("%lf", &radius);
printf("The area is %f!\n", areaOfCircle(radius));
break;
case 4:
system("clear");
printf("\n ~~ matrix *beta* ~~\n\n");
int numRows;
int numColumns;
printf("\nPlease enter the number of rows:");
scanf("%d", &numRows);
printf("\nPlease enter the number of columns:");
scanf("%d", &numColumns);
buildMatrix(numRows, numColumns);
break;
default:
printf("\n Incorrect input, try again.\n");
};
return 0;
};