C/C++ :: Read In Numeric Representation Of Date And Prints It Out In Formatted Manner

Oct 13, 2014

Write a program that reads in the numeric representation of a date and prints it out in a formatted manner as the box below.

1. If the user entered an invalid number for the month it should display "Invalid Month"
2. If the user entered an invalid number for the date it should display "Invalid Date"
3. Check to see if the day is outside the range for that particular month

An example of the input and the output:
Enter the date: 1 24 2013
The date you entered is: 1242013

Im not sure on how to go about this problem, but this is what I have.

#include <stdio.h>
int main(void) {
int a, b, c;
int status;
printf("Enter the Date");
status = scanf("%d,%d,%d",&a, &b, &c);
printf("
The Date is : %d
",status);
return 0;
}

Am I going about this right? Is there an easier or better way to go about it? All that happens is that the program reads the first number and spits that back out.

View 5 Replies


ADVERTISEMENT

C++ :: Change Making Program Prints Correct Values But Prints Them In Loop

Jan 27, 2015

I have a program that makes change from an amount. It works fine, but the output is the correct output looped over and over. I have tried everything, but it still doesn't work. For example, a amount of 98 should print

3 quarters
2 dimes
0 nickles
3 pennies
but instead it prints
3 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies

Why it's doing this?

Code:
#include <iostream>
using namespace std;
int coinscount(int& amount, int value) {
int tracker = 0;
int amountdimes = amount;

[Code].....

View 3 Replies View Related

C++ :: Read Date From File To Determine Different Days?

Mar 22, 2014

How do I read a date from a file to determine different of days

For example my date.txt contains:

1 23/01/2012 05/02/2012

Currently my code is:

#include<iostream>
#include<fstream>
using namespace std;

[Code].....

View 14 Replies View Related

C/C++ :: Read Date From File To Determine Different Days

Mar 21, 2014

How do I read a date from a file to determine different of days

For example my date.txt contains:

1 23/01/2012 05/02/2012

Currently my code is:

#include<iostream>
#include<fstream>
using namespace std;
class Date {
public:
int day;
int month;
int year;
int total_day;
Date();

[Code] ....

View 1 Replies View Related

C++ :: Program Prints Correct Result But Prints It Over And Over

Feb 9, 2015

I have a program where the user inputs a line of integers, and then all unique ones are outputted. It works fine-almost. It prints the numbers correctly, but prints them more than once and I'm not sure why.

Code: #include <iostream>
using namespace std;
int main ( ) {

[Code]......

View 10 Replies View Related

C# :: How To Rearrange Lists In A Special Manner

May 15, 2014

how to rearrange lists in an special manner.

I have heard about the hashset but I do not fully understand how that thing works or if it is the best option for this issue.

Basically I have 3 lists: LIST1, LIST2 and LIST3.

LIST1 is a set of xyz points and LIST2 shows how the points are connected (clockwise, counter clockwise, coolinear).

For example the fact that in the first line of LIST2 appears 0, 1, 2,-1 means that the points in LIST1 are connected as follows:

(0 0 128.588459085565)->(25 0 134.979628462965)->(0 0 134.979628462965)

Same for line2 of LIST2: 1, 4, 2,-1

(25 0 134.979628462965)->(25 0 140.100717207301)->(0 0 134.979628462965)

etc...

The value -1 at the end of each line does not mean anything but I need to keep it.

Finally LIST3 tells me if the points are connected counterclockwise (-1), clockwise (1), or coolinear (0).

The thing is that I want to get things as follows:

If the values of list 3=1 then I need to extract all the points in the list 1 that correspond to the value 1 in order. However the values in LIST2 cannot keep being 1, 4, 2,-1 they need to be reorganised starting by zero. Expected result in LIST2= 0,3,1,-1.

We need to do this for each value in list3 (1,-1 and 0).

The idea is to get 3 groups of values:

- Group 1 including all the values that are clockwise (list3) with the points in order in list1 and showing connections starting from zero on in list2.

- Group 2 including all the values that are counterclockwise (list3) with the points in order in list1 and showing connections starting from zero on in list2.

- Group 3 including all the values that are coolinear (list3) with the points in order in list1 and showing connections starting from zero on in list2.

The idea is to be able to print 3 files in the following way:

FILE1:

Points which are clockwise in LIST 1
...

Connections of those points in LIST 2
...

FILE2:

Points which are counterclockwise in LIST 1

[code]....

View 5 Replies View Related

C++ :: Initialize A Class In A Manner Similar To C Arrays

Jan 6, 2015

In my case, it involves making a wrapper class of sorts for the std::set. I'm wanting to go all-out on it and make some "fashionable" constructors for it, one of which being similar to C-style array initializations.

// C-array initialization.
int array[5] = { 1, 2, 3, 4, 5 };

// Some example usage of what I'm wanting.
Set<long> num_set = { 10, 20, 30, 40, 50 };
Set<std::string> str_set = { "Hello", "I", "am", "a", "set." };

I almost never overload operators when I work--if it can be done with a function, it's done with a function--but I realize that doesn't make the best user-experience when other people come across your code, so that's what I'm trying to improve.

It looks like I'm going to be needing to overload the = operator, no big deal. But the array segment is confusing, since {} is not an overloadable operator in C++.

View 2 Replies View Related

C Sharp :: GET Values From Table In A Recursive Manner

Nov 14, 2013

I am trying to work with C# and i am stuck here. My problem is i want to retrieve the count of all the users in a specific side. Let me Explain. Here is my table snapshot with sample data.

Now what i want exactly is that i get the count of users in a specific side as i give a user id as a parameter.The data is stored in MS Sql Database and i have to implement this on a website so efficiency of code is also a issue.

Suppose i give 1001 as input
The output should be : Left:1 , Right: 8

if 1002 is input
The output should be : Left:5, Right:0

if 1003 is input
The output should be : Left:3, Right:0

if 1004 is input
The output should be : Left:0, Right:0

if 1005 is input
The output should be : Left:1, Right:1

and so on. how to implement this thing. I also want to get a code which would return an array of all child users of a particular ID in a hierarchical manner so that i could process that data with RadOrgChart Control.

Attached Images scr.png (14.9 KB, 36 views)

View 1 Replies View Related

C/C++ :: Given Person Birth-date Or Any Other Date Will Display Day Of Week

Oct 11, 2012

i'm making a program that, given a person's birthdate or any other date, will display the day of the week of the person was born.

There is this part where it says "use a switch statement to make this calculation, If desired month is 12, add the number of days for November, if desired month is 11 add the number of days for october....

So it's suppose to start with "case 12 :...

I can't figure out what to write for the statement....

View 6 Replies View Related

C++ :: Two Date Structures Sharing Same Date

Mar 28, 2014

I have two date/time structures which I'm populating, but when I populate the second one it sets the same values in the first. This is what I've got so far

tm *FirstDate = gmtime(&now);
tm *SecondDate = gmtime(&now);

cout <<"Enter your first date in the format dd/mm/yyyy" << endl <<">";
getline (cin,tempstring);

[Code] .....

View 2 Replies View Related

C++ :: Formatted Input Using Cin

Apr 28, 2013

I'm trying to use cin to get input in a specific format.

Say I have this string as an input: "+ Baraq 112540783 AB1234" I want my variables to look like that:

name = "Baraq"
id = 112540783
book = "AB1234"

now I am sure there is something with providing the format of the input " %s %s %s" or something like that, just not sure how to use it.

View 5 Replies View Related

C++ :: Reading FASTA Formatted Files?

Nov 27, 2013

reading fasta formatted files. Usually ppl from computation biology know what that is but for those that are not here is a quick guide :

Fasta formatted file:

Code: >header
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseq
>header1
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseq

... so a very simple file format. and what i need to do is to read that into memory (vector of strings) so that header info and seq info is in two different vectors. for that i am using the following function :

Code:

sequence and headers vectors are class variables:

template <typename TStr>
template <typename FS>
void FastaSeq<TStr>::ReadFasta(FS& fs){
string line;
string seq;
while (fs >> line){
if(line.c_str()[0] == '>'){

[code].....

this code does what is suppose to do but it is EXTREMELY slow. it takes me exponentially more time to read the seq in memory then to process it. when compared to c style alternative that reads character by character it takes 13 sec with this function to do the same job that my c function does in 0.03 sec. How to improve upon this function to make it comparably fast (also i am using optimization) ?

View 10 Replies View Related

C/C++ :: How To Parse CSV Formatted Text File

Aug 9, 2012

my data are
#saben~123~tvm~999999~local~#
#ach~123~tvm~999999~body~#
#sam~123~tvm~999999~wash~#
#sus~123~tvm~999999~area~#
#sach~123~tvm~999999~local~#

View 3 Replies View Related

C Sharp :: Convert XML Which Is In Multilines To Formatted XML

Jan 8, 2013

i have an xml which is in showing in multilines and the tags are not in single line and are discontinued in next line .I need to this xml to be in correct format and want to display as xml .

View 1 Replies View Related

C :: Base Number Representation

Jul 23, 2014

I am using MCC18 for use with MPLAB.

0bnnnnnnnn means a binary representation.
0x00 means a hex number representation.

What does sd001 means? signed decimal 1? if so how do I represent a -1 using this sdnnnn format?

View 3 Replies View Related

C :: Unsigned Integer Representation

May 15, 2014

Consider this piece of code from the following website: [URL] .....

Code:
unsigned intx = 50;
x += (x << 2) + 1;

The website above says the following about the code:

Although this is a valid manipulation, the result of the shift depends on the underlying representation of the integer type and is consequently implementation-defined.

How exactly would a legal left shift operation on an unsigned integer result in implementation-defined behaviour?

View 5 Replies View Related

C :: Reading Formatted Strings From Text File

Nov 28, 2014

I wanted to improve the game from my last thread. I want to read and store a question in this format: Code: Who invented the BALLPOINT PEN?

A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers

But when I use fgets() to read the string, it reads all the ' ' literally instead of outputting a real newline. Like if it read the above question, I want it to print something like this:

Code:
Who invented the BALLPOINT PEN?

A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers

View 3 Replies View Related

C++ :: Mixed Expressions / Loops And Formatted Output

Feb 22, 2015

1) ask the user to input a mathematical expression in the following format:

NUMBER Operator NUMBER Operator NUMBER
Example: 17 + 15 - 3
Example: 2 * 3 - 4

How to output the answer of the users equation. Is there a function that includes all math operators (+,-,/,*)? Would i need to write each possible scenario using if statements?

View 2 Replies View Related

C :: How To Convert Number 75 To Base 4 Representation

Mar 6, 2015

How to convert e.g. number 75 to base 4 representation? The result should be 1023. I plan to use uint32_t

x = a3.43 + a2.42 + a1.41 + a0.40 = a3.64 + a2.16 + a1.4 + a0

View 9 Replies View Related

C++ ::  Need Time Representation That Cannot Be Adjusted And Can Be Serialized

Jan 24, 2015

I'm looking for something that can hold the current time, but is independent of the user adjusting the OS's time, and that can be converted to a std::string and back and that meets the requirements of LessThanComparable and EqualityComparable, I search online but I couldn't find anything suitable.

I can't use The C++ Standard Chrono Library because:

std::chrono::system_clock you can change the OS's time
std::chrono::steady_clock and std::chrono::high_resolution_clock cannot be converted to a std::string and back

View 5 Replies View Related

C++ :: Floating Point Representation - Comparing With Zero

Nov 1, 2014

I'm currently trying to learn about floating point representation in depth, so I played around a bit. While doing so, I stumbled on some strange behaviour; I can't really work out what's happening...

#include <iostream>
#include <cmath>
using namespace std;
int main(){
float minVal = pow(2,-149); // set to smallest float possible
float nextCheck = ((float)((minVal/2.0f))); // divide by two

[Code] ....

Essentially what's happening is:
- I set minVal to be the smallest float that can be represented using single precision
- Dividing by 2 should yield 0 -- we're at the minimum
- Indeed, isZero2 does return true, but isZero returns false.

What's going on -- I would have thought them to be identical? Is the compiler trying to be clever, saying that dividing any number cannot possibly yield zero?

View 5 Replies View Related

C++ :: Adjacency List Graph Representation?

May 3, 2014

"My Programm is crashing and i dont know why?"

#include<iostream>
using namespace std;
int arr[3];
struct edges {
int edge_data;
edges *next;

[code]....

View 1 Replies View Related

C++ :: Formatted TXT File And Store Data Into Their Respective Members

Apr 16, 2014

The program is supposed to read a formatted .txt file and store the data into their respective [Class] Members. It will then output the data collected onto screen.I overloaded ifstream and istream. When I call for file>>ptr[i] to read the data, something goes wrong. It prompts me to input data (which is in istream overload).The Data in .txt file is as follows;

#ifndef STUDENTTESTSCORES_H
#define STUDENTTESTSCORES_H
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

[code]....

View 6 Replies View Related

C :: Compact Table Representation - Data Structure

Jul 19, 2013

Data structure problem. I have a table of the following format:

Code:
C/R 1 2 3 4 5 6 7 ...
1 x x x
2 x
3 x
4 x
5 x x x
6
... s

So my column and row names are integer numbers if an outcome of some game for a certain column and row lable is a match then we have an x on that position. The size of the integer names for both column and row name is quite large (let us imagine that it is so large that you would need a machine with 500GB of RAM memory to hold this type of table even if x's are treated as regular char's) . In every row there is at least one x and for every column the same holds for the columns. However, the number of x's for a row or a column can be bigger then 1. How to store this table efficiently? (using as less memory as possible).

The data structure should be efficiently accessed in the column fashion that is, if i want to get all values for column 4 I should be able to do that in O(N) time where N= the number of rows.

View 10 Replies View Related

C :: Storage Types / Formatted Input / Output / Processing A Menu

Feb 1, 2013

where to start and how it should be structured. how I should go about writing this program, like should i make functions, pointers, etc. And to display the menu, is it easiest to just use printf statements or is there something more efficient.

View 3 Replies View Related

C++ :: Creating String Representation Of Unsigned Char Bits

Mar 5, 2014

I need to convert the bit representation of an unsigned char into a string.

so like 254 would be "11111111"

I'm having some trouble where no matter what number I try to convert I get 01111111.

string bin2string(unsigned char N) {
string sN(8,'0');
unsigned char X;
unsigned char Y = 0;
for(int i = 0; i < 8; i++){

[Code] ....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved