formated code and renamed index.c to gui.c

This commit is contained in:
superdimensional 2021-04-18 15:31:26 -04:00
parent d53b048b9f
commit 34aae499f8
4 changed files with 163 additions and 157 deletions

View file

@ -1,5 +1 @@
# cli-algebra-calculator
cli-algebra-calculator
Make into apple store ios app and run ads on it?
Make into linux app

View file

@ -1,37 +1,41 @@
#include <math.h>
#include <stdio.h>
double exponent( double par){
double exponent(double par)
{
double raisedNum;
raisedNum = par * par;
return raisedNum;
};
double hypotenuse(double par, double par2){
double hypotenuse(double par, double par2)
{
double sideC;
sideC = sqrt( exponent(par) + exponent(par2) );
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);
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 awn2 = (-numB) - sqrt(exponent(numB) - 4 * numA * numC);
double awn2F = awn2 / (2 * numA);
*awn1ptr = awn1F;
*awn2ptr = awn2F;
};
double areaOfCircle(double radius){
double areaOfCircle(double radius)
{
double area;
area = acos(-1) * exponent(radius);
return area;
}
@ -39,26 +43,26 @@ 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 i = 0; i < numRows; i++)
{
for(int j = 0; j < numColumns; j++)
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 i = 0; i < numRows; i++)
{
for(int j = 0; j < numColumns; j++)
for (int j = 0; j < numColumns; j++)
{
printf("%d ", matrix[i][j]);
}
printf("\n");
}
return 0;
}

View file

@ -3,81 +3,84 @@
#include <stdbool.h>
//import C libraries
//gcc -Wall -Werror -pedantic -std=c11 index.c `pkg-config --cflags --libs gtk+-3.0`
//gcc -Wall -Werror -pedantic -std=c11 gui.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");
printf("1 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>1</span>");
"<span font='Italic 30'>1</span>");
}
void on_show_button_2_clicked(GtkWidget *show_button2, GtkWidget *hello_display)
{
printf("2 has been clicked\n");
printf("2 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>2</span>");
"<span font='Italic 30'>2</span>");
}
void on_show_button_3_clicked(GtkWidget *show_button3, GtkWidget *hello_display)
{
printf("3 has been clicked\n");
printf("3 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>3</span>");
"<span font='Italic 30'>3</span>");
}
void on_show_button_4_clicked(GtkWidget *show_button4, GtkWidget *hello_display)
{
printf("4 has been clicked\n");
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)
"<span font='Italic 30'>4</span>");
}
void on_show_button_5_clicked(GtkWidget *show_button5, GtkWidget *hello_display)
{
printf("5 has been clicked\n");
printf("5 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>5</span>");
"<span font='Italic 30'>5</span>");
}
void on_show_button_6_clicked(GtkWidget *show_button6, GtkWidget *hello_display)
{
printf("6 has been clicked\n");
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)
"<span font='Italic 30'>6</span>");
}
void on_show_button_7_clicked(GtkWidget *show_button7, GtkWidget *hello_display)
{
printf("7 has been clicked\n");
printf("7 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>7</span>");
"<span font='Italic 30'>7</span>");
}
void on_show_button_8_clicked(GtkWidget *show_button8, GtkWidget *hello_display)
{
printf("8 has been clicked\n");
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)
"<span font='Italic 30'>8</span>");
}
void on_show_button_9_clicked(GtkWidget *show_button9, GtkWidget *hello_display)
{
printf("9 has been clicked\n");
printf("9 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>9</span>");
"<span font='Italic 30'>9</span>");
}
void on_show_button_0_clicked(GtkWidget *show_button0, GtkWidget *hello_display)
{
printf("0 has been clicked\n");
printf("0 has been clicked\n");
gtk_label_set_markup(GTK_LABEL(hello_display),
"<span font='Italic 30'>0</span>");
"<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)
@ -99,13 +102,13 @@ void build_window(void)
show_button1 = gtk_button_new();
show_button2 = gtk_button_new();
show_button3 = gtk_button_new();
show_button3 = gtk_button_new();
show_button4 = gtk_button_new();
show_button5 = gtk_button_new();
show_button5 = gtk_button_new();
show_button6 = gtk_button_new();
show_button7 = gtk_button_new();
show_button7 = gtk_button_new();
show_button8 = gtk_button_new();
show_button9 = 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");
@ -117,46 +120,46 @@ void build_window(void)
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();
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_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_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_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_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_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_CALLBACK(on_show_button_0_clicked),
hello_display);
g_signal_connect(clear_button, "clicked",
G_CALLBACK(on_clear_button_clicked),
hello_display);
G_CALLBACK(on_clear_button_clicked),
hello_display);
/* Create a layout element to visually organize widgets. */
layout = gtk_grid_new();
@ -193,11 +196,12 @@ void build_window(void)
* 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);
NULL);
}
/* main() function called when program starts. */
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
/* Call the gtk initialization function */
gtk_init(&argc, &argv);

138
main.c
View file

@ -3,7 +3,10 @@
#include <stdlib.h>
#include "functions.h"
int main (){
// to compile use "gcc main.c -lm"
int main()
{
system("clear");
printf("Welcome to Calculator Collection™.\nPlease select which calculator you would like to use.");
printf("\n\n 1. Hypotenuse calculator");
@ -13,83 +16,82 @@ int main (){
printf("\n\n Enter your choice here:_____");
printf("\033[D");
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);
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("The Hypotnuse is equal to %f.\n", hypotenuse(sideA, sideB));
break;
case 2:
system("clear");
printf("\n ~~ Quadratic formula calculator ~~\n\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("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);
printf("The Hypotnuse is equal to %f.\n", hypotenuse(sideA, sideB));
break;
double awn1ptr, awn2ptr;
quadratic(numA, numB, numC, &awn1ptr, &awn2ptr);
case 2:
system("clear");
printf("\n ~~ Quadratic formula calculator ~~\n\n");
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");
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 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;
double awn1ptr, awn2ptr;
quadratic(numA, numB, numC, &awn1ptr, &awn2ptr);
default:
printf("\n Incorrect input, try again.\n");
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;
};
};