C++ program...please DO NOT code with or for Visual Studio!!! The last \"expert\
ID: 666517 • Letter: C
Question
C++ program...please DO NOT code with or for Visual Studio!!!
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 *note this is a header file AND a driver file!
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, AGAIN PLEASE!
Explanation / Answer
1)
list.h
-------------
ListNode(double v, ListNode *p);
private:
double data; //class variables declared
ListNode *next;
friend class LinkedList; //implementing new class
};
#include <list.h>
#include <iostream>
using namespace std;
class ListNode
{
public:
ListNode(double v, ListNode *p) //construcctor declared
{
data = v; next = p;
}
class LinkedList
{
public:
LinkedList( ) { head = NULL;}
~LinkedList();
void insert(double x, int pos);
private:
ListNode * head;
};
//inserting at required position
void LinkedList::insert(double x, int pos)
{
//cecking for inserting beginninng
if ( pos == 0 || head == NULL)
{
head = new ListNode(x, head);
return;
}
//checking for nodes skipping..count
ListNode *p = head;
int skip = 1;
while (skip <= pos) //skipping nodes to insert inbetween nodes
{
if (p->next == NULL || skip == pos)
{
p->next = new ListNode(x, p->next);
return;
}
p = p->next;
skip++;
}
}
int main()
{
LinkedList list; //list object creating
for (int k = 1; k <= 5; k++)
{
cout << " In which position you want to enter: ";
int x, position;
cin>>position;
cout<<"Enter value";
cin>>x;
list.insert(x,position); //inserting
}
system("pause");
return 0;
}
------------------------------------------------------------------
2)
DynQueue.h
queue <string> students; //queue declaration
DynQueue.cpp
#include <DynQueue.h>
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
queue <string> students; //queue declaration
students.push ("john"); // adding data
students.push ("Corn");
students.push ("Akon");
cout << "Now " << students.size () << " Students in the queue" << endl;
students.pop (); //removing one student
cout << "Now " << students.size () << " Students in the queue" << endl;
return EXIT_SUCCESS;
}
----------------------------------------
3)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
cout << "Enter date to convert:";
int month, day, year; // variables declared
char monthword, dayWord;
cin >> month, day, year;
switch(month) //switch case..as per month
{
case 1: if (day <=31)
cout << monthword << "January";
else cout << monthword << "Exception: wrong input";
break;
case 2: if ((day >= 1) && (day <=28)) {
cout << monthword << "Febuary";
}
else cout << monthword << "Exception: wrong input";
break;
case 3: if ((day >= 1) && (day <=31)) {
cout << monthword << "March";
}
else cout << monthword << "Exception: wrong input";
break;
case 4: if ((day >= 1) && (day <= 30)) {
cout << monthword << "April";
}
else cout << monthword << "Exception: wrong input";
break;
case 5: if ((day >= 1) && (day <= 31)) {
cout << monthword << "May";
}
else cout << monthword << "Exception: wrong input";
break;
case 6: if ((day >= 1) && (day <=30)) {
cout << monthword << "June";
}
else cout << monthword << "Exception: wrong input";
break;
case 7: if ((day >= 1) && (day <= 31)) {
cout << monthword << "July";
}
else cout << monthword << "Exception: wrong input";
break;
case 8: if ((day >=1) && (day <= 31)) {
cout << monthword << "August";
}
else cout << monthword << "Exception: wrong input";
break;
case 9: if ((day >= 1) && (day <= 30)) {
cout << monthword << "September";
}
else cout << monthword << "Exception: wrong input";
break;
case 10: if ((day >=1) && (day <= 31)) {
cout << monthword << "October";
}
else cout << monthword << "Exception: wrong input";
break;
case 11: if (( day >=1) && (day <= 30)) {
cout << monthword << "November";
}
else cout << monthword << "Exception: wrong input";
break;
case 12: if (( day >=1) && (day <=31)) {
cout << monthword << "December";
}
else cout << monthword << "Exception: wrong input";
break;
default : cout << monthword << "Exception: wrong input";
break;
}
if (day == 1 || day == 21 || day ==31) //printing [refixed to words
cout << dayWord << "st,";
else if (day == 2 || day == 22)
cout << dayWord << "nd,";
else if (day == 3 || day == 23)
cout << dayWord << "rd,";
else
cout << dayWord << "th,";
cout << monthword << day << dayWord << year << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.