7. File Reading 1 (Points: 30)
1This question has a bonus part (c) worth 10 points.
Consider an input file "data.dat" of the following format (one string and one int number). The data is meant to represent a person and his/her age.
Bob 20
Joe 30
Mary 10
.....
a) (10 points) Determine a data type that is suitable to hold this information in memory. Select a data type that does not require any knowledge about the number of lines in the file. You might want to create a base type (a class) to store the name and the age and a sequential container type (a vector) whose elements are of the type of this class.
b) (20 points) Write a complete program that handles the reading of this file. Structure the program so that a main function defines the necessary data and data types.
The actual reading is done by a function that takes the data structure as a parameter that will be changed in the function. The function opens the file, reads its content and stores the read data in e
Does anyone know how to write the prigram for this it will C++?
Yes, I know how to write the program for this.
pear
Sunday, August 2, 2009
How do i Find Difference between two date and Time in C programming?
I have Date in String format. The Date is of format YYYYMMDDHH24MISS
Eg :- 20071102121007
I need to find the difference in Minutes.
I also need to Validate if this date and time is of Right Format Eg: - Date cannot be more than 31 and Hour Time cannot be more than 24 Hours and Etc.
Do you know any Pre-Defined functions for this ???
Or Any Good Logic that can Help me ??? I think this is possible in Unix Shell Scripting
But I need it in C. Plz Help
How do i Find Difference between two date and Time in C programming?
#include %26lt;iostream%26gt;
#include %26lt;ctime%26gt;
int main()
{
struct std::tm a = {0,0,0,24,5,104}; /* June 24, 2004 */
struct std::tm b = {0,0,0,5,6,104}; /* July 5, 2004 */
std::time_t x = std::mktime(%26amp;a);
std::time_t y = std::mktime(%26amp;b);
if ( x != (std::time_t)(-1) %26amp;%26amp; y != (std::time_t)(-1) )
{
double difference = std::difftime(y, x) / (60 * 60 * 24);
std::cout %26lt;%26lt; std::ctime(%26amp;x);
std::cout %26lt;%26lt; std::ctime(%26amp;y);
std::cout %26lt;%26lt; "difference = " %26lt;%26lt; difference %26lt;%26lt; " days" %26lt;%26lt; std::endl;
}
return 0;
}
Eg :- 20071102121007
I need to find the difference in Minutes.
I also need to Validate if this date and time is of Right Format Eg: - Date cannot be more than 31 and Hour Time cannot be more than 24 Hours and Etc.
Do you know any Pre-Defined functions for this ???
Or Any Good Logic that can Help me ??? I think this is possible in Unix Shell Scripting
But I need it in C. Plz Help
How do i Find Difference between two date and Time in C programming?
#include %26lt;iostream%26gt;
#include %26lt;ctime%26gt;
int main()
{
struct std::tm a = {0,0,0,24,5,104}; /* June 24, 2004 */
struct std::tm b = {0,0,0,5,6,104}; /* July 5, 2004 */
std::time_t x = std::mktime(%26amp;a);
std::time_t y = std::mktime(%26amp;b);
if ( x != (std::time_t)(-1) %26amp;%26amp; y != (std::time_t)(-1) )
{
double difference = std::difftime(y, x) / (60 * 60 * 24);
std::cout %26lt;%26lt; std::ctime(%26amp;x);
std::cout %26lt;%26lt; std::ctime(%26amp;y);
std::cout %26lt;%26lt; "difference = " %26lt;%26lt; difference %26lt;%26lt; " days" %26lt;%26lt; std::endl;
}
return 0;
}
What is the best way of sending the "enter" key manually, by code, in C?
I have a program that types in a custom-made code-defined "command" but I do not know how to have the code "press enter" after the command.
For related background, this is for terminal use:
Prompt) Enter a command
Prompt) exit.now //How to have the program press enter here is the issue.
In C++, I have seen that you can use sendkey(s), but how do you do it in C?
I had one idea that I could use fopen and fprintf with stdin.
What is the best way of sending the "enter" key manually, by code, in C?
Not exactly sure what you are asking, however,
ioctl() is the common method of setting up the terminal.
Are you writing a DOS program? Unix????
Is this a human interacting or a program interacting with another program?
if program to program, you can use piping
Reply:try appending "\r\n" to your command string.
For related background, this is for terminal use:
Prompt) Enter a command
Prompt) exit.now //How to have the program press enter here is the issue.
In C++, I have seen that you can use sendkey(s), but how do you do it in C?
I had one idea that I could use fopen and fprintf with stdin.
What is the best way of sending the "enter" key manually, by code, in C?
Not exactly sure what you are asking, however,
ioctl() is the common method of setting up the terminal.
Are you writing a DOS program? Unix????
Is this a human interacting or a program interacting with another program?
if program to program, you can use piping
Reply:try appending "\r\n" to your command string.
Friday, July 31, 2009
Given real numbers a,b,c,d, let, f : R(squared) go to R(squared) be defined by f(x, y) = (ax+by, cx+dy)?
How to prove that f is injective if and only if (iff) f is surjective.
Given real numbers a,b,c,d, let, f : R(squared) go to R(squared) be defined by f(x, y) = (ax+by, cx+dy)?
suppose that f is injective,
to prove: f is surjective
if f is injective then
f(1,0) = (a,c)
and
f(0,1) = ( b,d) are linearly independent vectors.
but since the dimension of R^2 is 2, then these vectors are a basis, and so
any vector (z,w) can be written as a linear combination of (a,c) and (b,d)
(z,w) = A(a,c) + B(b,d)
=( Aa + Bb, Ac+Bd)
take (x,y) = (A,B)
then f(x,y) = ( Aa + Bb, Ac+Bd) = (z,w)
thefore f is surjective.
If f is surjective, then any vector (z,w) = f(x,y) for some (x,y).
Given real numbers a,b,c,d, let, f : R(squared) go to R(squared) be defined by f(x, y) = (ax+by, cx+dy)?
suppose that f is injective,
to prove: f is surjective
if f is injective then
f(1,0) = (a,c)
and
f(0,1) = ( b,d) are linearly independent vectors.
but since the dimension of R^2 is 2, then these vectors are a basis, and so
any vector (z,w) can be written as a linear combination of (a,c) and (b,d)
(z,w) = A(a,c) + B(b,d)
=( Aa + Bb, Ac+Bd)
take (x,y) = (A,B)
then f(x,y) = ( Aa + Bb, Ac+Bd) = (z,w)
thefore f is surjective.
If f is surjective, then any vector (z,w) = f(x,y) for some (x,y).
Hey guys n gals need someone good in c to take on this one will send u my feedback after ur result thanks?
How can one Implement a function in C that takes an array of integers,%26amp; and reverses the order of items in the
The function you implement must have the following form:
void reverse_order(int array[], int n)
{
/* your code goes here: re-order the n items in the array so that the
first one becomes the last
* * and the last one first.
*/
}
You should then implement a main() function which reads in a set of integers into an array,
reverses the order of the number (using the function you have just defined) and prints them out
again.
For example, when complete and compiled, you should be able to run your program, and enter
the numbers:
2 4 5 11 23 1 4
then program will then print out:
4 1 23 11 5 4 2
make sure your program will allow the user enter the numbers and then gives the output as their reverse
Hey guys n gals need someone good in c to take on this one will send u my feedback after ur result thanks?
do your own homework. this is actually a very easy exercise - a simple loop is all that is needed.
nobile
The function you implement must have the following form:
void reverse_order(int array[], int n)
{
/* your code goes here: re-order the n items in the array so that the
first one becomes the last
* * and the last one first.
*/
}
You should then implement a main() function which reads in a set of integers into an array,
reverses the order of the number (using the function you have just defined) and prints them out
again.
For example, when complete and compiled, you should be able to run your program, and enter
the numbers:
2 4 5 11 23 1 4
then program will then print out:
4 1 23 11 5 4 2
make sure your program will allow the user enter the numbers and then gives the output as their reverse
Hey guys n gals need someone good in c to take on this one will send u my feedback after ur result thanks?
do your own homework. this is actually a very easy exercise - a simple loop is all that is needed.
nobile
In C#, how can you access only the selected text in a cell defined by the DataGridTextBoxColumn class?
For example, if a textbox in a DataGrid contains "little" but the user has only selected "li", how can I see programmatically that the user selected "li"?
In C#, how can you access only the selected text in a cell defined by the DataGridTextBoxColumn class?
Unfortunately, .NET doesn't have this as a built-in property or method for the DataGridTextBox control.
If you are working on a Web page, you could access that information client-side via JavaScript's Selected property.
In C#, how can you access only the selected text in a cell defined by the DataGridTextBoxColumn class?
Unfortunately, .NET doesn't have this as a built-in property or method for the DataGridTextBox control.
If you are working on a Web page, you could access that information client-side via JavaScript's Selected property.
When he became president, Franklin D. Roosevelt a,b,c,or d?
a. was a self amde man businessman who had little sympathy for disadvantaged americans
b. had to convince businessmen that government had a role to play in ending the depression
c. had a progresssives faith in the power of government to solve problems
d. had a clearly defined program that he was convinced would end the depression
When he became president, Franklin D. Roosevelt a,b,c,or d?
B
Reply:B
Reply:D, but he still got frustrated
Reply:b.
Reply:B and D
Reply:d.
b. had to convince businessmen that government had a role to play in ending the depression
c. had a progresssives faith in the power of government to solve problems
d. had a clearly defined program that he was convinced would end the depression
When he became president, Franklin D. Roosevelt a,b,c,or d?
B
Reply:B
Reply:D, but he still got frustrated
Reply:b.
Reply:B and D
Reply:d.
Subscribe to:
Posts (Atom)