Question about Computers & Internet

Hi,

a 6ya expert can help you resolve that issue over the phone in a minute or two.

best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.

the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).

click here to download the app (for users in the US for now) and get all the help you need.

goodluck!

Posted on Jan 02, 2017

Where to begin?

Easy: FIND SUITABLE LIBRARY

answer is easy, but finding is hard enough.

Hopefully c++ standart has time.h that has functions you need.

Without any talking source code below:

I created 2 files: data.h which has classes and functions and main.cpp :)

-----------------data.h-----------------

#ifndef _DATA_H_

#define _DATA_H_

#include <time.h>

class Data

{

public:

time_t rawtime; // time.h requres this

struct tm *timeinfo; // and this also

public:

Data(); // constructor

int getMonth();

int getDay();

int getYear();

char *getAll();

};

class Time : public Data // child funqcion

{

public:

int getH();

int getM();

int getS();

};

Data::Data() // copy of constructor

{

time(&rawtime);

timeinfo = localtime(&rawtime);

}

int Data::getMonth()

{

return timeinfo->tm_mon;

}

int Data::getDay()

{

return timeinfo->tm_wday;

}

int Data::getYear()

{

return timeinfo->tm_year;

}

char *Data::getAll()

{

return asctime(timeinfo);

}

int Time::getH()

{

return timeinfo->tm_hour;

}

int Time::getM()

{

return timeinfo->tm_min;

}

int Time::getS()

{

return timeinfo->tm_sec;

}

#endif

----------------------END OF FILE--------------------

I hope you know include file rule when working with multiple files. I mean you understand #ifndef and #define...

and the main.cpp:

#include "data.h"

#include <iostream>

//I hope you understand all this...

using namespace std;

Data myData;

Time myTime;

const char *months[12] =

{

"January",

"Febryary",

"March",

"April",

"May",

"June",

"Jule",

"August",

"September",

"October",

"November",

"December",

};

const char *days[7] =

{

"Sunday",

"Monday",

"Tuesday",

"Wednesday",

"Thursday",

"Friday",

"Saturday",

};

int gmonth;

int gday;

int gyear;

int ghour;

int gmin;

int gsec;

char *compact; // why char *compact and not char compact? because Data.getAll returns *char

int main(int argc, char *argv[])

{

cout << "Getting month...\n";

gmonth = myData.getMonth();

cout << "Current month: " << months[gmonth];

cout << endl;

cout << "Getting week day...\n";

gday = myData.getDay();

cout << "Current week day: " << days[gday];

cout << endl;

cout << "Getting year...\n";

gyear = myData.getYear() + 1900; // +1900 is necessary :) because year is calculating after 1900

cout << "Current year: " << gyear;

cout << endl;

cout << "Getting hour...\n";

ghour = myTime.getH();

cout << "Current hour: " << ghour;

cout << endl;

cout << "Getting minutes...\n";

gmin = myTime.getM();

cout << "Current minutes: " << gmin;

cout << endl;

cout << "Getting seconds...\n";

gsec = myTime.getS();

cout << "Current seconds: " << gsec;

cout << endl;

cout << endl;

compact = myData.getAll(); // Coolest one :)

cout << compact << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

----------------END OF FILE--------------------

I clearly don't understand what set hours, minutes, secs mean:'

Tested and working.

If you have any questions write comment.

I compiled this project in DevCpp, but it will work for Visual Studio too.

This might be different what you expected but solve any problem AS EASY AS POSSIBLE in programming. Solve problem i mean everything is working.

Aah, I've written a lot :)

Please rate my solution...

And Successful Programming!

Easy: FIND SUITABLE LIBRARY

answer is easy, but finding is hard enough.

Hopefully c++ standart has time.h that has functions you need.

Without any talking source code below:

I created 2 files: data.h which has classes and functions and main.cpp :)

-----------------data.h-----------------

#ifndef _DATA_H_

#define _DATA_H_

#include <time.h>

class Data

{

public:

time_t rawtime; // time.h requres this

struct tm *timeinfo; // and this also

public:

Data(); // constructor

int getMonth();

int getDay();

int getYear();

char *getAll();

};

class Time : public Data // child funqcion

{

public:

int getH();

int getM();

int getS();

};

Data::Data() // copy of constructor

{

time(&rawtime);

timeinfo = localtime(&rawtime);

}

int Data::getMonth()

{

return timeinfo->tm_mon;

}

int Data::getDay()

{

return timeinfo->tm_wday;

}

int Data::getYear()

{

return timeinfo->tm_year;

}

char *Data::getAll()

{

return asctime(timeinfo);

}

int Time::getH()

{

return timeinfo->tm_hour;

}

int Time::getM()

{

return timeinfo->tm_min;

}

int Time::getS()

{

return timeinfo->tm_sec;

}

#endif

----------------------END OF FILE--------------------

I hope you know include file rule when working with multiple files. I mean you understand #ifndef and #define...

and the main.cpp:

#include "data.h"

#include <iostream>

//I hope you understand all this...

using namespace std;

Data myData;

Time myTime;

const char *months[12] =

{

"January",

"Febryary",

"March",

"April",

"May",

"June",

"Jule",

"August",

"September",

"October",

"November",

"December",

};

const char *days[7] =

{

"Sunday",

"Monday",

"Tuesday",

"Wednesday",

"Thursday",

"Friday",

"Saturday",

};

int gmonth;

int gday;

int gyear;

int ghour;

int gmin;

int gsec;

char *compact; // why char *compact and not char compact? because Data.getAll returns *char

int main(int argc, char *argv[])

{

cout << "Getting month...\n";

gmonth = myData.getMonth();

cout << "Current month: " << months[gmonth];

cout << endl;

cout << "Getting week day...\n";

gday = myData.getDay();

cout << "Current week day: " << days[gday];

cout << endl;

cout << "Getting year...\n";

gyear = myData.getYear() + 1900; // +1900 is necessary :) because year is calculating after 1900

cout << "Current year: " << gyear;

cout << endl;

cout << "Getting hour...\n";

ghour = myTime.getH();

cout << "Current hour: " << ghour;

cout << endl;

cout << "Getting minutes...\n";

gmin = myTime.getM();

cout << "Current minutes: " << gmin;

cout << endl;

cout << "Getting seconds...\n";

gsec = myTime.getS();

cout << "Current seconds: " << gsec;

cout << endl;

cout << endl;

compact = myData.getAll(); // Coolest one :)

cout << compact << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

----------------END OF FILE--------------------

I clearly don't understand what set hours, minutes, secs mean:'

Tested and working.

If you have any questions write comment.

I compiled this project in DevCpp, but it will work for Visual Studio too.

This might be different what you expected but solve any problem AS EASY AS POSSIBLE in programming. Solve problem i mean everything is working.

Aah, I've written a lot :)

Please rate my solution...

And Successful Programming!

May 08, 2012 | HP Computers & Internet

I believe you're asking for a loop that will output that sequence specifically. One way to go about it is with the following code:

for (int i = 0; i < 3; i++)

{

if (i == 0)

cout << i+1 << endl;

else if (i == 1)

cout << i + 1 << i << endl;

else

cout << i +1 << i << i - 1 << endl;

}

I know the hard coded numbers is a bit inelegant, but in this case this snippet of code will solve the problem.

for (int i = 0; i < 3; i++)

{

if (i == 0)

cout << i+1 << endl;

else if (i == 1)

cout << i + 1 << i << endl;

else

cout << i +1 << i << i - 1 << endl;

}

I know the hard coded numbers is a bit inelegant, but in this case this snippet of code will solve the problem.

Aug 24, 2011 | Microsoft Visual C++ 6.0 Professional...

#include <iostream>

using namespace std;

int main ()

{

int num = 0, i = 1, sum = 0;

cout << "Enter a positive integer: ";

cin >> num;

while (i <= num)

{

sum += i;

i++;

}

cout << "The sum is " << sum << endl;

return 0;

}

using namespace std;

int main ()

{

int num = 0, i = 1, sum = 0;

cout << "Enter a positive integer: ";

cin >> num;

while (i <= num)

{

sum += i;

i++;

}

cout << "The sum is " << sum << endl;

return 0;

}

Oct 30, 2010 | Compaq Visual Fortran Professional Edition...

hi,

here is the code u looking for

#include <iostream.h>

using namespace std;

float sub (float a, float b)

{

float dif;

dif=a - b;

return dif;

}

float addition (float c, float d)

{

float sum;

sum=c+d;

return sum;

}

float divi (float e, float f)

{

float quo;

quo = e/f;

return quo;

}

float multi (float f, float g)

{

float pro;

pro=f * g;

return pro;

}

int main ()

{

float a;

float b;

float opt;

cout << "Welcome to the calculator" << endl;

cout << "There are four options " << endl;

cout << "Option 1 is subtraction, Option 2 is addition, option 3 is division, and option 4 is multiplication " << endl;

cout << "Enter your option and two digits " << endl;

cin >> opt >> a >> b;

if (opt == 1)

{

float temp= sub (a, b);

cout << "Your difference is " << temp << endl;

}

else

if (opt==2)

{

float temp2= addition (a, b);

cout << "Your sum is " << temp2 << endl;

}

else

if (opt == 3)

{

float temp3= divi (a,b);

cout << "Your quotient is " << temp3 << endl;

}

else

if (opt == 4)

{

float temp4= multi (a,b);

cout << "Your product is " << temp4 << endl;

}

else

{

cout << "That function is not supported in calculator!" << endl;

}

cout << "Thank you for using calculator" << endl;

return 0;

}

Thanks!

here is the code u looking for

#include <iostream.h>

using namespace std;

float sub (float a, float b)

{

float dif;

dif=a - b;

return dif;

}

float addition (float c, float d)

{

float sum;

sum=c+d;

return sum;

}

float divi (float e, float f)

{

float quo;

quo = e/f;

return quo;

}

float multi (float f, float g)

{

float pro;

pro=f * g;

return pro;

}

int main ()

{

float a;

float b;

float opt;

cout << "Welcome to the calculator" << endl;

cout << "There are four options " << endl;

cout << "Option 1 is subtraction, Option 2 is addition, option 3 is division, and option 4 is multiplication " << endl;

cout << "Enter your option and two digits " << endl;

cin >> opt >> a >> b;

if (opt == 1)

{

float temp= sub (a, b);

cout << "Your difference is " << temp << endl;

}

else

if (opt==2)

{

float temp2= addition (a, b);

cout << "Your sum is " << temp2 << endl;

}

else

if (opt == 3)

{

float temp3= divi (a,b);

cout << "Your quotient is " << temp3 << endl;

}

else

if (opt == 4)

{

float temp4= multi (a,b);

cout << "Your product is " << temp4 << endl;

}

else

{

cout << "That function is not supported in calculator!" << endl;

}

cout << "Thank you for using calculator" << endl;

return 0;

}

Thanks!

Mar 19, 2009 | Microsoft Computers & Internet

Hi,

a very simple example scriptlet:

#include <iostream>

int main()

{

using namespace std;

int i=1;

do

{

cout << "value of i:" << i << endl;

} while (i<=10);

return 0;

}

Thanks.

a very simple example scriptlet:

#include <iostream>

int main()

{

using namespace std;

int i=1;

do

{

cout << "value of i:" << i << endl;

} while (i<=10);

return 0;

}

Thanks.

Mar 17, 2009 | Microsoft Visual Basic 6.0 for PC

When it comes to else, if, or else-if statements, once you understand how they work you will be laughing. It is not very difficult to understand, and for all C/C++ programmers (New or Experienced alike) I would suggest reading the information and tutorials located at http://www.cprogramming.com/tutorial.html

This is a great resource site for any C/C++ programmers out there, especially if you have been single tasked and forgot how to do something.

This is a great resource site for any C/C++ programmers out there, especially if you have been single tasked and forgot how to do something.

Feb 13, 2009 | Microsoft Computers & Internet

#include<iostream.h>

void main()

{

int a[10],i,n,x;

cout<<"\n\t\tPROGRAM TO DELETE AN NUMBER FROM AN ARRAY";

cout<<"\nEnter the size of the array:";

cin>>n;

for(i=0;i<n;i++)

{

cout<<"\nEnter the number:";

cin>>a[i];

}

cout<<"\nEnter the position to be deleted:";

cin>>x;

for(i=x;i<n;i++)

a[i]=a[i+1];

for(i=0;i<n-1;i++)

cout<<a[i]<<" ";

}

Oct 13, 2008 | Computers & Internet

An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier

Initializing arrays. When declaring a regular array of local scope (within a function, for example), if we do not specify otherwise, its elements will not be initialized to any value by default, so their content will be undetermined until we store some value in them. The elements of global and static arrays, on the other hand, are automatically initialized with their default values, which for all fundamental types this means they are filled with zeros

include <iostream>

using namespace std;

int billy [] = {16, 2, 77, 40, 12071};

int n, result=0;

int main ()

{

for ( n=0 ; n<5 ; n++ )

{

result += billy[n];

}

cout << result;

return 0;

}

multidimensional array pseudo-multidimensional array #define WIDTH 5 #define HEIGHT 3 int jimmy [HEIGHT][WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n][m]=(n+1)*(m+1); } return 0; } #define WIDTH 5 #define HEIGHT 3 int jimmy [HEIGHT * WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n*WIDTH+m]=(n+1)*(m+1); } return 0; }

and now for trignometry

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int factorial(int);

int n = 3, i = 1;

double x, x2, b, PI, r;

char choice;

//r = x * (PI / 180)

cout<<"Please enter an angle value => ";

cin>>x;

cout<<"Is the angle value in Degree or Radian?"<<endl;

cout<<"Type D if its in degree "<<endl;

cout<<"Type R if its in radian "<<endl;

cin>>choice;

if((choice = 'R')||(choice = 'r'))

do{

i++; n = 3; x2 = 0; b = x2;

{

if(i == 1)

x2 = x - (pow(x,n) /factorial(n));

n = n + 2;

};

else

{

x2 = (x2 + ((pow(x,n)) /(factorial(n))) - (pow(x,n+2)) / (factorial(n+2)));

n = n + 4;

}

}while(abs(b - x2) > 0.000001);

else

//convert it to r

r = x * PI /180;

//cout<<"error occured/n";

cout<<"sin(x) = "<<x2<<endl;

return 0;

}

Initializing arrays. When declaring a regular array of local scope (within a function, for example), if we do not specify otherwise, its elements will not be initialized to any value by default, so their content will be undetermined until we store some value in them. The elements of global and static arrays, on the other hand, are automatically initialized with their default values, which for all fundamental types this means they are filled with zeros

include <iostream>

using namespace std;

int billy [] = {16, 2, 77, 40, 12071};

int n, result=0;

int main ()

{

for ( n=0 ; n<5 ; n++ )

{

result += billy[n];

}

cout << result;

return 0;

}

multidimensional array pseudo-multidimensional array #define WIDTH 5 #define HEIGHT 3 int jimmy [HEIGHT][WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n][m]=(n+1)*(m+1); } return 0; } #define WIDTH 5 #define HEIGHT 3 int jimmy [HEIGHT * WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n*WIDTH+m]=(n+1)*(m+1); } return 0; }

and now for trignometry

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int factorial(int);

int n = 3, i = 1;

double x, x2, b, PI, r;

char choice;

//r = x * (PI / 180)

cout<<"Please enter an angle value => ";

cin>>x;

cout<<"Is the angle value in Degree or Radian?"<<endl;

cout<<"Type D if its in degree "<<endl;

cout<<"Type R if its in radian "<<endl;

cin>>choice;

if((choice = 'R')||(choice = 'r'))

do{

i++; n = 3; x2 = 0; b = x2;

{

if(i == 1)

x2 = x - (pow(x,n) /factorial(n));

n = n + 2;

};

else

{

x2 = (x2 + ((pow(x,n)) /(factorial(n))) - (pow(x,n+2)) / (factorial(n+2)));

n = n + 4;

}

}while(abs(b - x2) > 0.000001);

else

//convert it to r

r = x * PI /180;

//cout<<"error occured/n";

cout<<"sin(x) = "<<x2<<endl;

return 0;

}

Mar 24, 2008 | ArcMedia JavaScript Source Code 3000 Pro...

Jan 23, 2017 | Computers & Internet

Jan 23, 2017 | Computers & Internet

Jan 23, 2017 | Computers & Internet

29 people viewed this question

Usually answered in minutes!

×