C++ :: Converting Month Number To Month Name Using Exception Classes
Oct 29, 2013
program that prompts the user to enter a person’s date of birth in numeric form such as 8-27-1980.The program then outputs the date of birth in the form: august 27, 1980.Your program must contain at least two exception classes; invalidDay and invalidMonth.
I write this program to print the number of days for the month when the year and the month enters. This is not giving any result and i think that problem is with calling functions.
#include<iostream> #include<conio.h> #include<string> using namespace std; int leap_year(int year); string days(string mounth); string feb(string fab1); void main(){ int year;
Whenever I run the program I get no errors yet it doesn't return a value for total it just exits the program. The program is supposed to output the number of the day based on the month day and year and check whether it is a leap year.
#include <iostream> using namespace std; int totaldays(); int days(); int month, day, year; bool leap(); int main() { char dash; cout << "Enter the date in mm-dd-yyyy format to find out what day this is in the year." << endl;
I'm trying to determine the first Tuesday of any month in a given year.. I'd prefer to use my own functions to arrive at a solution, but logically I could sorting these things out.
I am having trouble associating the month names with the month numbers. When the program runs, it should output the date in three styles.
Also I do not know if my input validations work correctly(day cannot be greater than 31 or less than 1, month cannot be greater than 12 or less than 1).
#include <iostream> using namespace std; char again; class Date { private: int month; int day; int year;
The objective is to build a month class that hold data on the number of the month and the name of the month. Using constructors and overloads, set it up to where you can input either the month or the name and it will output the results for both the month number and name.
Here is the code I have so far:
#include<iostream> #include<string> using namespace std; class Month{ private: string name; int monthNumber;
[Code] ....
It is almost fully compiled if I go by the error list. The only problems I see to be having are with the prefix and postfix overloads.
So for my C++ class I am required to create a program that will "Write a program to generate a calendar for a year. The program should accept the year and the day of the week for january 1 of that year (0=Sunday, 1=Monday, etc.)" (problem statement) and I am completely stuck. I've posted what I have so far below:
#include <iostream> #include <iomanip> using namespace std;
bool isLeapYear(int year); int daysInMonth(int month, bool lpYear); int printCalendar(int month); int printDay(int dow);
(I'm using visual c++). Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following:
A) Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the balance.
B) Ask the user for the total amount withdrawn from the account during that month. Do not accept negative numbers or numbers greater than the balance after the deposits for the month have been added in.
C) Calculate the interest for that month. The monthly interest rate is the annual interest rate divided by 12. Multiply the monthly interest rate by the average of that month’s starting and ending balance to get the interest amount for the month. This amount should be added to the balance.
After the last iteration, the program should display a final report that includes the following information:
• starting balance at the beginning of the three-month period. • total deposits made during the three months • total withdrawals made during the three months • total interest posted to the account during the three months • final balance.
What I need is to solve that particular problem using a class. Here is the code solved for the problem not using a class:
#include<iostream> using namespace std; int main() { double annulInterestRate, balance, monthlyInterestRate,
In this assignment the student should develop a month calendar by designing a class called calendarType . This class uses two other classes (dateType and dayType) as described below:
1. dayType Class: This class has been designed by students in Lab1 exercises. Referee to it. 2. dateType Class: This class is designed and implemented to keep track of data. This class has been provided it to you. Study it first then add definitions and implementations of the following operations to this class:
- Test whether the year is a leap year. Leap year is identified by 3 criteria : - The year is evenly divisible by 4; - If the year can be evenly divided by 100, it is NOT a leap year, unless; - The year is also evenly divisible by 400. Then it is a leap year. - Return the number of days in the month. For example, if the date is 12/3/2014, the number of days to be returned is 31 because there are 31 days in March. - Return the number of days passed in the year. For example, if the date is 18/3/2014 the number of days passed is 77. Note that the number of days returned also includes the current day. - Return the number of days remaining in the year. For example, if the date is 18/3/2014 , the number of days remaining in the year is 288. - Calculate the new date by adding a fixed number of days to the date. For example, if the date is 18/3/2014 and the days to be added are 25, the new date is 12/4/2014.
To print monthly calendar using calendarType class, you must know the first day of the month and the number of the days in that month. Thus, you must store the first day of the month, which is in the form of dayType and the month and the year of the calendar. Clearly, the month and the year can be stored as an object of the form dateType by setting the day component of the date to 1, and the month and year as specified by user.
Design the class calendarType so that the program print a calendar for any month starting 1/1/ 1500 which is Monday. To calculate the first day of a month, you can add the 2 appropriate days to Monday of January 1, 1500. For this class identify and implement the following operations:
- Determine the first day of the month for which the calendar will be printed. Call this operation firstDayOfMonth. - set/get month. - set/get year. - Print calendar for particular month. - Add the appropriate constructors to initialize the member variables. - Write a test program to print the calendar for either a particular year or a particular month.
I'm having trouble converting a 4 digit number into a BCD number, in the program I did below I was able to convert a 2 digit number into BCD, but I do not know how to convert a 4 digit number or how to start it.
#include <cstdlib> #include <iostream> #include <string> using namespace std; int main(int argc, char *argv[])
I'm a games/apps developer and right now I'm developing games/apps for iOS, Android and also PC / Facebook. I've also been working on C++ for some time but since I'm learning it all by myself, I still have some beginner doubts.
Is there any easy way to code a value conversion (for example an octal value to an actual number)?
I am working on an assignment about converting an integer number to its 2's complement presentation. The binary representation is consisting of a single linked list.
As we all know, the steps of this converting is to taking the reminder of the absolute value, then flipping the 1 to be 0, and the 0 to be 1 in the binary number. And the last step will be to add 1 to the binary number invers.
I wrote a code that implements every thin correctly. However, when I reached the part of adding 1, the program was hanged.
int Absolute; //the first step is to convert the number to the binry reprezentation Absolute = abs (value);// by take the Absolute value of the negative number, then find the while (Absolute !=0) //the binary reprezentation { int res; res= (Absolute % 2); pushFront (res); Absolute /=2 ;
The program is supposed to convert a two digit hexadecimal number to its binary representation. My code runs without any problems but I do not know how to limit the user's input to two digits only. For example the person can input "1ABC" and the program will give the binary representation and I need it to only accept two digit only like for example "1A".
#include<stdio.h> #define MAX 1000 int main(){ char binaryNumber[MAX],hexaDecimal[MAX]; long int i=0; printf("Enter a two digit hexadecimal number: ");
Write a program in c++ to accept a number and convert this number into binary or hexa decimal or octal number according to the user choice using the concept of array.
Store the result into an array D of 8 elements. Your program should show the decimal numbers for every binary number. Print screen of 6 answers. This means you should try your program six times with different numbers in every run and show the printed screen result.
I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");
// In Manager.h #include"Student.h" class Manager {
I catch an exception and want to log it on the console. This works as exepcted, but Valgrind shows me a set of invalid reads.
Here the code of the catch-block:
} catch(HGL::IOException &e) { logError(e); }
The signature of the logDebug is: BasicLogger &operator<<(const std::exception &e);
Now valgrind shows me 4 errors like that:
==20943== Invalid read of size 1 ==20943== at 0x402C658: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==20943== by 0x41554DD: std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& std::operator<< <wchar_t, std::char_traits<wchar_t> >(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&, char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
[Code] .....
Generally I dislike invalid read in my code, even if they are harmless like in that case.
If I don't pass a reference, but a copy of the exception, I don't get this invalid reads, but also loose all information, because of the implicit upcasting.
Why I get the illegal read, resp. why std::wstring is deleting it on the way to the <<-operator?
I'm trying to do some operator overloading, the function is supposed to add the values at index [i] of two vectors and place the result in the returning vector. The problem is I keep getting a vector out of range. This is the overloaded operator I'm working with (relatively new to these):
vector<float> operator+(const vector<float>& a, const vector<float>& b){ unsigned long size; vector<float> temp; if(a.size() >= b.size()) size = a.size();
[Code] .....
and then I would do something like this in the main:
vector<float> v, v1, v2;
v1.push_back(9.1); ... v2.push_back(8); ... v = v1 + v2;
but when I try to output the vector v I just get a vector out of range exception.
I'm making an "improved" array for my programing class. It's currently unfinished, so you might see some commented out code. I'm trying to debug what I have.
I keep getting these errors when I try to complile my main.cpp:
In file included from main.cpp:3:0:
array.h:107:43: error: expected type-specifier before ‘out_of_range’ array.h:107:43: error: expected ‘)’ before ‘out_of_range’ array.h:107:43: error: expected initializer before ‘out_of_range’ array.h:121:55: error: expected type-specifier before ‘out_of_range’ array.h:121:55: error: expected ‘)’ before ‘out_of_range’ array.h:121:55: error: expected initializer before ‘out_of_range’
My main file:
#include <iostream> #include <stdexcept> #include "array.h" using namespace std; using namespace ArrayNameSpace; int main() { Array<int> testSubject(5); return 0; }//End main
aannnd my Array.h file:
//ADD CONSTS TO METHODS //CURRENTLY WORKING ON EXCEPTIONS AND BRACKET[] OVERLOADS. I HAVE TO FIGURE OUT SOLUTIONS FOR REACHING //INDEXES FOR CHARS AND ENUMS #ifndef __array_H__ #define __array_H__ #include <stdexcept> namespace ArrayNameSpace {
I have been assigned to create a search function in text file, but I received this error when I run the program and try to search: Error message: Unhandled exception at 0x0f85d442 (msvcr100d.dll) in Ticket.exe: 0xC0000005: Access violation reading location 0xcccccd08.
I don't know what is the exactly problem. So I just copy everything and paste here. Please don't fear of these codes, I have 2 files only, but I will paste 3 files here, the one is prototypes.h, then the main.cpp, the last one is part of my function that can working well alone, but when I put them into main.cpp I will get the error message like I mentioned before.