C/C++ Beginner's Guide and Post Basic Questions here

what does the thing in bold mean?

Yes you can do it using string.

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

int main()
{
fstream file;
string line;

file.open("E:\\abc.txt", ios::in);

while(getline(file, line))
cout << line << endl;

return 0;
}
 
Last edited:
why php? what is ios::in??

Its C++ code enclosed in
PHP:
 tag. Edited it :wink:

ios::in is the file opening mode. When you open a file, you have to specify the opening mode. It can be read only, white only, append with in, out, app being their specifiers. These file openning specifiers reside in ios class (not sure if its a class), hence, the use of ios::in. If the file were to be apened for writing only, then it would be ios::out.
 

kunalht

In the zone
please suggest a C/C++ software for ubuntu (linux).
I am new to ubuntu.
So please suggest a good software with compiler with download links.
also tell me some good softwares for linux.
 

Chaitanya

Cyborg Agent
please suggest a C/C++ software for ubuntu (linux).
I am new to ubuntu.
So please suggest a good software with compiler with download links.
also tell me some good softwares for linux.

I have no programming experience on linux tho heard it has inbuilt libs for C compilers.
You may try GCC(GNU Compiler Collection)GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF)

You may try notepad++ for editing & creating codes..
 

aaruni

The Linux Guy
Can anyone tell me why this program only prints "<year> is not a leap year." ?

Code:
/*
Fourth problem
input -> num year
output -> if leap year -> true , else -> false (write proper interface)
conditions of leap year : divisible by 4 !by 100 but by 400
*/
#include<iostream>
using namespace std;
int main()
{
	int year,limb1,limb10,limb40;
	cout<<"Program to tell whether a given year is a leap year or not.\nPlease enter the year to be checked.\n\t";
	cin>>year;
	limb1=year%4;
	if (limb1 == 0)
	{
		limb10 = year%100;
		limb40 = year%400;
		if (limb40 == 0)
		{
			if (limb10 > 0)
			{
				cout<<year<<" is a leap year.\n";
			}
			else if (limb10 == 0)
			{
				cout<<year<<" is not a leap year.\n";
			}
		}
		else
		{
			cout<<year<<" is not a leap year.\n";
		}
	}
	else
	{
		cout<<year<<" is not a leap year.\n";
	}
	return 0;
}
 

Chaitanya

Cyborg Agent
It was a logical error on my part. Corrected here : C/C++ Thread

Well you could have written program a lot smaller..
Couldn't get why you required 3 conditions while it is solved by one.

Well problem is solved & only that matters. ;-)
 

aaruni

The Linux Guy
condition of a leap year are specified in the program comments.

conditions of leap year : divisible by 4 !by 100 but by 400
 

rohitshubham

Ambassador of Buzz
so, i was doing a code and submitting it online i encountered a problem i.e. when i submit code #1 it accepts the solution but when i try code #2 it gives wrong answer , but as far as i know, the logic is same. plz help.
code no 1:
Code:
int main(){
  int T;
  long int R;
  long int x1,y1;
  long int x2,y2;
  long int x3,y3;
  long int d1,d2,d3;
 
  scanf("%d",&T);
  while(T > 0) {
    scanf("%d",&R);
    scanf("%d %d",&x1,&y1);
    scanf("%d %d",&x2,&y2);
    scanf("%d %d",&x3,&y3);
    R = pow(R,2);
    d1 = pow((x1-x2),2) + pow((y1-y2),2);
    d2 = pow((x1-x3),2) + pow((y1-y3),2);
    d3 = pow((x2-x3),2) + pow((y2-y3),2);
    if((d1 <= R && d2 <= R) || (d2 <= R && d3 <= R) || (d1 <= R && d3 <= R)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
 
    T--;
  }  /* while */
  return 0;
}
code no 2:
Code:
int main(){   int test;
    float x1,x2,x3,y1,y2,y3,r;
    float dis1,dis2,dis3;
    cout<<"enter test cases";
    cin>>test;
    while(test--)
    {
        cin>>r>>x1>>y1>>x2>>y2>>x3>>y3;
        dis1= pow((x1-x2),2) + pow((y1-y2),2);
        dis2=pow((x2-x3),2)+ pow((y2-y3),2);
        dis3=pow((x1-x3),2)+pow((y1-y3),2);
        r=pow(r,2);
        if((dis1<=r && dis2<=r)||(dis1<=r && dis3<=r)||(dis3<=r && dis2<=r))
            cout<<"yes";
        else
            cout<<"no";


    }
    return 0;
}
 
Last edited:
Top Bottom