The last \"expert\" didn\'t read the caveat below...I NEED THIS TO WORK IN A GCC
ID: 666409 • Letter: T
Question
The last "expert" didn't read the caveat below...I NEED THIS TO WORK IN A GCC LINUX COMPILER...NOT VISUAL STUDIO!
THIS HAS TO BE CODED IN A GCC COMPILER AND NOT VISUAL STUDIO!!! PLEASE!!! IF IT'S A VISUAL STUDIO CPP FILE IT IS OF NO USE TO ME!!!
COP 1335C Lab 25 points 1) Linked List (10 points) File names: NumberList.h NumberListMain.cpp Modify the linked list class (NumberList) that we created in class to include the following member function: void insertByPosition(double x, int pos); The function should insert x at a specified position, pos. A position of 0 means that the value will become the first item in the list, 1 means the second item, and so on. A position equal to or greater than the length of the list means that the value is placed at the end of the list. Test your function in main(). Be sure to fully test the function(insert in beginning of list, middle of list, end of list, empty list, etc.) 2) Template classes (10 points) File names: DynQueue.h, DynQueue.cpp Queue Template Using the DynIntQueue class we defined in class, create a DynQueue class template. Once you have your class template, write a small main() program that exercises all of the class member functions for a minimum of two “types” of Queues. 3) Exception Handling (5 points) File name: monthday.cpp Write a program that converts dates from numerical month/day format to alphabetic month/day (for example1/31 or 01/31 corresponds to January 31). Throw a string exception if the user enters anything other than a legal month number (integers from 1 to 12. Similarly, throw a string exception if the user enters an invalid day number (integers from 1 to either 29, 30, or 31, depending on the month). To keep things simple, always allow 29 days for February. Test your code by catching your exception.
AGAIN...PLEASE CODE THIS FOR A GCC COMPILER...LEAVE THE VISUAL STUDIO STUFF OUT OF IT! I DON'T WANT TO WASTE ANOTHER QUESTION, PLEASE!
Explanation / Answer
Hi,
If you want to execute the program in GCC complier i think the program can be written in 'c' programming and executed using gcc complier.Hope that's what you are looking for?
Answers:
Question 1: To implement void insertByPosition(double x, int pos); function.
/*
* C Program to Implement Singly Linked List using Dynamic Memory Allocation
*/
#include <stdio.h>
#include <malloc.h>
#define ISEMPTY printf(" EMPTY LIST:");
/*
* Node Declaration
*/
struct node
{
int value;
struct node *next;
};
stnode* create_node(int);
void insert_node_first();
void insert_node_last();
void insert_node_pos();
void display();
typedef struct node snode;
stnode *newnode, *ptr, *prev, *temp;
stnode *first = NULL, *last = NULL;
/*
*Main Function
*/
int main()
{
int charcter;
char answer = 'Y';
while (answer == 'Y'||answer == 'y')
{
printf(" --------------------------------- ");
printf(" Operations on singly linked list ");
printf(" --------------------------------- ");
printf(" 1.Insert node at first");
printf(" 2.Insert node at last");
printf(" 3.Insert node at position");
printf(" 4.Display List from Beginning till end");
printf(" 5.Exit ");
printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ");
printf(" Enter your choice");
scanf("%d", &ch);
switch (charcter)
{
case 1:
printf(" Inserting node at first ");
insert_node_first();
break;
case 2:
printf(" Inserting node at last ");
insert_node_last();
break;
case 3:
printf(" Inserting node at position ");
insert_node_pos();
break;
case 4:
printf(" Displaying List From Beginning till the End ");
display();
break;
case 5:
printf(" Exiting ");
return 0;
break;
default:
printf(" ...Invalid Choice... ");
break;
}
printf(" YOU WANT TO CONTINUE (Y/N)");
scanf(" %c", &answer);
}
return 0;
}
/*
* Creating Node dynamically assigning value to the node using the malloc
*/
stnode* create_node(int value)
{
newnode = (stnode *)malloc(sizeof(stnode));
if (newnode == NULL)
{
printf(" Memory is not allocated");
return 0;
}
else
{
newnode->value = value;
newnode->next = NULL;
return newnode; //Returns the new node created
}
}
/*
* Inserting Node at First we are populating the linked list with values
*/
void insert_node_first()
{
int value;
printf(" Enter the value for the node:");
scanf("%d", &value);
newnode = create_node(value);
if (first == last && first == NULL)
{
first = last = newnode;
first->next = NULL;
last->next = NULL;
}
else
{
temp = first;
first = newnode;
first->next = temp;
}
printf(" ----INSERTED AT THE START OF LIST----");
}
/*
* Inserting Node at Last we are populating the linked list with values
*/
void insert_node_last()
{
int value;
printf(" Enter the value for the Node:");
scanf("%d", &value);
newnode = create_node(value);
if (first == last && last == NULL)
{
first = last = newnode;
first->next = NULL;
last->next = NULL;
}
else
{
last->next = newnode;
last = newnode;
last->next = NULL;
}
printf(" ----INSERTED AT THE END OF THE LIST----");
}
/*
* Inserting Node at position
*/
void insert_node_pos()
{
int pos, value, cnt = 0, i;
printf(" Enter the value for the Node:");
scanf("%d", &value);
newnode = create_node(value);
printf(" Enter the position ");
scanf("%d", &pos);
ptr = first; //If this node is the first node we make this as the first node of the list
while (ptr != NULL)
{
ptr = ptr->next;
cnt++;
}
if (pos == 1)
{
if (first == last && first == NULL)
{
first = last = newnode;
first->next = NULL;
last->next = NULL;
}
else //If this is not the first node then node will be inserted at the desired position
{
temp = first;
first = newnode;
first->next = temp;
}
printf(" Inserted");
}
else if (pos>1 && pos<=cnt)
{
ptr = first;
for (i = 1;i < pos;i++)
{
prev = ptr;
ptr = ptr->next;
}
prev->next = newnode;
newnode->next = ptr;
printf(" ----INSERTED----");
}
else
{
printf("Position is out of range");
}
}
/*
* Displays non-empty List from Beginning till the End
*/
void display()
{
if (first == NULL)
{
ISEMPTY;
printf(":No nodes are present in the list to display ");
}
else
{
for (ptr = first;ptr != NULL;ptr = ptr->next)
{
printf("%d ", ptr->value);
}
}
}
Output:
$gcc linkedlist.c
a.out
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter your choice4
Displaying List From Beginning till the End
EMPTY LIST::No nodes are present in the list to display
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice
3
Inserting node at position
Enter the value for the Node:99999
Enter the position 5
Position is out of range
YOU WANT TO CONTINUE (Y/N)
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice
Enter your choice1
...Inserting node at first...
Enter the value for the node:55
----INSERTED----
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice1
Inserting node at first
Enter the value for the node:65
----INSERTED----
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice4
Displaying List From Beginning to End
55 65
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice2
Inserting node at last
Enter the value for the Node:150
----INSERTED----
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice4
Displaying List From Beginning to End
55 65 150
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice3
Inserting node at position
Enter the value for the Node:75
Enter the position 4
----INSERTED----
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice4
Displaying List From Beginning to End
55 65 150 75
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice3
Enter the value for the Node:85
Enter the position 10000
Position is out of range
YOU WANT TO CONTINUE (Y/N)y
---------------------------------
Operations on singly linked list
---------------------------------
1.Insert node at first
2.Insert node at last
3.Insert node at position
4.Display List from Beginning till end
5.Exit
Enter your choice3
Enter the value for the Node:85
Enter the position 5
----INSERTED----
YOU WANT TO CONTINUE (Y/N)n
Note:I have tested for all these scenarios insert in beginning of list, middle of list, end of list, empty list.
Question 2:I need more clearity on what actually should be implemented here.I am not sure about the question itself.Please provide me information on what you need.
Question 3:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
printf ("Enter date in numerical format separated by spaces:";
// month calculations
int month, day, year, year1; // integer variables
printf (month >> day >> year); // user inputs numeric date format
switch(month)
{
case 1: if ((day <=0) || ( day <=32))
printf("January ");
else
printf("invalid # january days");
break;
case 2: if ((day >= 0) || (day <=29)) {
printf ("Febuary ");
}
else cout << "invalid # Febuary days";
break;
case 3: if ((day >= 0) || (day <=32)) {
printf("March ");
}
else
printf ("invalid # March days");
break;
case 4: if ((day >= 0) || (day <= 31)) {
printf("April ");
}
else
printf("invalid # April days");
break;
case 5: if ((day >= 0) || (day <= 32)) {
printf("May ");
}
else
printf("invalid # may days");
break;
case 6: if ((day >= 0) || (day <=31)) {
printf("June ");
}
else
printf("invalid # of June days");
break;
case 7: if ((day >= 0) || (day <= 32)) {
printf("July ");
}
else
printf("invalid # of july days");
break;
case 8: if ((day >=0) || (day <= 32)) {
printf("August ");
}
else
printf("invalid # of August days");
break;
case 9: if ((day >= 0) || (day <= 31)) {
printf("September ");
}
else
printf("invalid # of September days");
break;
case 10: if ((day >=0) || (day <= 32)) {
printf("October ");
}
else
printf("invalid # of October days");
break;
case 11: if (( day >=0) || (day <= 31)) {
printf ("November ");
}
else
printf("invalid # of November days");
break;
case 12:
if (( day >=0) || (day <=32)) {
printf ("December ");
}
else
printf("invalid # of December days");
break;
default : printf("invalid Month #");
break;
}
if (day == 1 || day == 21 || day ==31)
printf(day,"st, ");
else if (day == 2 || day == 22)
printf( day,"nd, ");
else if (day == 3 || day == 23)
printf(day , "rd, ");
else
printf(day , "th, ");
{
if (year <= 50)
year1 = 2000 + year;
else if (year >= 50 || year <= 99)
year1 = 1900 + year;
else
printf("Invalid Year #");
}
printf("year1");
return 0;
}
Note:http://cs-fundamentals.com/c-programming/how-to-compile-c-program-using-gcc.php
This link gives you information on how to run c program in gcc compiler.
Hope that helps.HAPPY ANSWERING!!!!!!!!!!!!!!!!!!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.