hinduengg 26 Junior Poster in Training

Ok I will try my best to do so and ask my problems. Wish me luck. Its not easy but i hope with your giudance I would be able to understand it better .
Thank you once again Narue .

Killer_Typo commented: actively working towards finding a solution is daniweb at it's finest! +5
hinduengg 26 Junior Poster in Training

Thanks a lot, lot. I really needed this help. Thank you.The example is superb. I really needed it.

I had just one small request that please could you please advice a good site that gives in depth analysis of C++ programming.
I will keep on trying , but I need guidance.
There are so many good sites for C but not for C++. Or perhaps I need to focus on C , derive the ideas and do programs in C++ according to C++ rules .
I really need to understand this . Its very important for my exam. I am in search of excellent C++ tutorials who could guide me through.
Please , please help.

hinduengg 26 Junior Poster in Training

Thanks Killer Typo and Narue.


I understand about random nos. now.
But regards insertion sort , the site 's code is in c not in c++ and i long for C++ for it doesn't have ->signs , I believe, I understand pointers to some extent but not struct that well , I wondered whether you could simplify it with C++ syntax and using for loops. Is there any established site where I can get syntax only pertaining to C++ like the eternally confused.


Please help and advice,
hinduengg

hinduengg 26 Junior Poster in Training

I haven't yet started this assignment for I have to submit my E.V.S PROJECT within the next 2 days , so I am really busy in that.

On another note, I wanted to know what are actually random nos., because I have often seen all of you using it quite a many times.

hinduengg 26 Junior Poster in Training

Thank you so much for the SUPERB explanation .

Now I would try out a program that implements insertion sort and see to it whether I am successful .

Loads of thanks once again. :)

hinduengg 26 Junior Poster in Training

Thank you dougy83 . What is meant by function-insert ?I wished you could give the example in cplusplus syntax for I have to use it in C++.
If an array is inputted like this:

if the array is- [2][7][3][9][4]
then how will insertion sorting occur to sort it.

will it take out first 2
then read the entire array for finding next - 3
then again after entire process- 4
then next in the order would be-7
then -9
so that the ordered array comes to
[2][3][3][7][9]

Please explain, I can not get it :(

hinduengg 26 Junior Poster in Training

Hi to all ,

I wished if any one of you could throw light on mechanism of insertion sorting in C++. I know what is bubble sorting but I had confusion regarding what is insertion sorting? In school my professor had mentioned about it, but I do not have any idea about it. :(
I got mixed up. I searched for it at the net but no clear ideas were given. It has been confusing for 7 days!!
I am unable to go about it.
I would appreciate if you could give an example of it ,so that i can understand it better.
Please help.

Thanks in advance.:)
Hinduengg

hinduengg 26 Junior Poster in Training

Well Narue is really right. Not only her explainations are perfect but also her links proved worthy to me. You must surely check the links given by her as they use latest trend of C++ and are precise and accurate.

hinduengg 26 Junior Poster in Training

Thank you .

hinduengg 26 Junior Poster in Training

Actually I have been trying to change my member profile features for quite some time but did not succeed . Wish any one could help me.
The member profile page has something called "Member Certificate"
but I do not what is it?

hinduengg 26 Junior Poster in Training

You could perhaps have a look at
www.cprogramming.com/tutorial/lesson11.html
also

hinduengg 26 Junior Poster in Training

So what is it that you basically require? - an array of removed duplicate integers , or printing the array once with no duplicates but containing those nos which previously had a duplicate along with the remaining numbers of the array . Please clarify this doubt.
May be then , even I can try to offer some aid like a nice member of Dani web.

hinduengg 26 Junior Poster in Training
#include <iostream>
#include <cstring>
                           // for strlen() [length of word]

using namespace std;

int main()
{
    char a[100];
     cout<<"enter your word"<<endl;     
    cin.getline(a,100);   // User input
    int l;
    l=strlen(a); // Length of input word
    int i;
    i = 0;
    while (i < len)  // the string always has last index for '\0'
    { 
  switch (a[i])
        {
        case 'a' : 
        case 'A' : cout << " Alpha";
        break; 
        case 'b' :
        case 'B' : cout << " Bravo";
        break;
        case 'c' :
        case 'C' : cout << " Charlie";
        break;
        case 'd' : 
        case 'D' : cout << " Delta";
        break; 
        case 'e' :
        case 'E' : cout << " Echo";
        break;
        case 'f' :
        case 'F' : cout << " Foxtrot";
        break;
        case 'g' : 
        case 'G' : cout << "Golf";
        break; 
        case 'h' :
        case 'H' : cout << " Hotel";
        break;
        case 'i' :
        case 'I' : cout << " India";
        break;
        case 'j' : 
        case 'K' : cout << " Kilo";
        break; 
        case 'l' :
        case 'L' : cout << " Lima";
        break;
        case 'm' :
        case 'M' : cout << " Mike";
        break;
        case 'n' : 
        case 'N' : cout << "November";
        break; 
        case 'o' :
        case 'O' : cout << " Oscar";
        break;
        case 'p' :
        case 'P' : cout << " Papa";
        break;
        case 'q' : 
        case 'Q' : cout << "Quebec";
        break; 
        case 'r' :
        case 'R' : cout << " Romeo";
        break;
        case 's' :
        case 'S' : cout << " Sierra"; …
hinduengg 26 Junior Poster in Training

Hello even i would try to help.
It ca be simple like this

in int main() you can incorporate a few more lines:

int choice;
        cout<<"enter your choice";
        cin>>choice;
        if(choice==1)
  search(collection,4,albumname);
else
cout<<"no  album found"
cin.get();
return 0;
}

void search(Album collection[], int size, string albumName) 
     { 
    for(int i = 0; i < size; i++)            
    {
        if(collection[i].albumName == albumName)    
        {                        
                   cout<<albumName<<" by " <<collection[i].artistName<<'\n';    
            for(int sl = 0; sl < size; sl++)    
      
                cout<<'\t'<<collection[i].songList[sl].title<<" on Track # "
                    <<collection[i].songList[sl].track<<"."<<'\n';    
            }
        }
    }

Besides I have a question that why have you declared albumname of string type 2 times.

One in struct Album the other in main()?

hinduengg 26 Junior Poster in Training

Yes Narue is absolutely right. Thank you for informing me too.

hinduengg 26 Junior Poster in Training

Sorry that a stands for myString forgot to modify it ,now it is better and it prints each charecter on a separate line

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
int main()
{
  char myString[100];
  cout<<"Your statement"<<endl;
  if(cin.get(myString,100))
    cout<<myString<<endl;
   else
    exit(0);
  return 0;
}

Perhaps you could try out this but I have used at least once the concept of char array which is also called c-style string in C++

// these header files do not exist in latest
version of c++ but runs on my Turbo C++
very well out you could try out the logic
with your setup //

(exit(0) is a function to terminate the program after your work is over you may use it if you wish and is accessible from process.h)

Actually my college still accepts the old look of C++
Best of luck for your tour in C++

hinduengg 26 Junior Poster in Training
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
int main()
{
  char myString[100];
  cout<<"Your statement"<<endl;
  if(cin.get(myString,100))
    cout<<a;
   else
    exit(0);
  return 0;
}

Perhaps you could try out this but I have used at least once the concept of char array which is also called c-style string.
// these header files do not exist in latest
version of c++ but runs on my Turbo C++
very well out you could try out the logic
with your setup //

You should use -usingnamespacestd for C++

(exit(0) is a function to terminate the program after your work is over you may use it if you wish and is accessible from process.h)

Actually my college still accepts the old look of C++
Best of luck for your tour in C++

hinduengg 26 Junior Poster in Training

Thank you for clearly stating. I would definitely read the links for that would make the concept lucid , unlike my book which makes it so complex!

Thank you once again .

hinduengg 26 Junior Poster in Training

Could you please give some info regarding - What are basically linked lists . I know that they can be used as arrays and stacks and queues.

But confused a bit about FIFO and LIFO CONCEPTS. I cant understand how do we always access the stack from top.It is just like an array or is it entirely different.

I could not understand it in class.

Please help.

hinduengg 26 Junior Poster in Training

You can also access this link for C++

http://www.cprogramming.com.html

It is a very good link for polishing anyone's basics about C++!

Hoping you would benefit , all the best!

hinduengg 26 Junior Poster in Training

I would say that you first start reading the book acoording to your course and if you have any queries,solve it in this forum.I think that is the best way to reach your goal.
Practice makes a person perfect.
So you could even try out simple problems given here and in whichever book you are following .
Focus initially on basic fundamentals-like datatypes,loops,functions,constructors,pointers and classes and objects.
You will find them at cplusplus.com easily.
Then proceed towards building up of complex ideas which even I find difficult.There is nothing to be worried about.You have to be simple in approach.Your view shold be crystal clear about what you come across. May it might help you.
Get the latest information regarding everything if not from the book,then you could choose this forum.
Best of luck!

hinduengg 26 Junior Poster in Training

Very well.I am getting it. With the link I would be able to understand about syntax for creation of n sized 1D,2D ARRAYS of char and int type for that is one thing that I cant understand at all and learn.

By the way I want to make sure that concept of and use of pointers is same in both Cand C++
for i am restricted to C++

Thank you for taking up so much pains .I will not tax you more for now.Even my college cant explain as well as you do.Thank you once again

hinduengg 26 Junior Poster in Training

By input stream you refer to Array and whitespace-blank?
Or it is the same stream which we use in file operations.
I generally deal with arrays of char size-100.For this means that it will store upto 100 charecters .Right?

Thank you ,I am reading about poniters
by the link you send

You are really nice in explainations

hinduengg 26 Junior Poster in Training

Narue thank you for informing me about latest trend of C++
I still use Turbo C++ which accepts .h header files.Even in my college the same old setup is followed.
Definitely after finals I would install the latest hardware.
I am sure now thats why a lot of members use std strings and the info you gave and not string.h

and no char arrays in C++

I am sorry Bops for giving you old info

hinduengg 26 Junior Poster in Training

Thank you a lot for the timely help.You have cleared the biggest doubt regarding C++ strings.
But here I request you to tell me

if ( cin>> n ) {
char (*words) = new char[n];


My professor has not taught about pointers for that is not in course but I
think to learn it .
Please could you explain this line to me as it as poniters.
I know one thing that pointers indicate to a value but after that no clue.
Please do not be irritated.I am trying to understand.I assume that is just the syntax.
right? But this for 2-d array of char type but on Left you have used 1-d char array

I think you are again using 2 D array as 1D array

Similarly it will be
int n;
int *a[100]=new[n];(for integer types)

char*wd=new[n];(for 1-d char array)

while(i<n && cin>>setw(100)>>words;


Besides what is meant by overfilling of the array that you use setw() here.
I have beentold that it is used to specify minimum no. of charecter positions on the output field
a varaible will consume.

PLEASE PERTAIN TO ONLY C++ FOR THATS IN MY SYLLABUS

hinduengg 26 Junior Poster in Training

You are welcome.

Perhaps I think that if you write a program in C++ then you should include header files with extension - .h
and if use C then you should use haeder fies like -<iostream>
and <cstring> etc. as Narue said because both are different programming languages.

Compilation errors might occur otherwise.

hinduengg 26 Junior Poster in Training

I think the same .Bops you must use it as in C++

#include<iostream.h>
#include<stdio.h>
  void main()
{
   char a[100];
   cout<<"enter your sentence";
   gets(a);
   for(int x=0;a[x]!='\0';x++)
   { 
         if(a[x]=='|')
          a[x]=' ';
  cout<<a[x];
  }
  
}

This in C++ may be it might help you in C
The logic is correct.

hinduengg 26 Junior Poster in Training

I TRIED YOUR SOLUTION AND IT IS WORKING WELL .

I again got it but this time very easily .Your solution was very accurate,
but in this case we will have to give the no. of strings entered initially like you have given it 10

same way should it be
int n;
cin>>n;
words[n][100];

By the way could you tell me how do we daclare char arrays of "n-size".Its dynamic allocation right?

hinduengg 26 Junior Poster in Training

True, but in this case...not so much of an issue. That solution is rather poorly implemented and overly complex. If you're going to use a multidimensional array, the problem is trivial and takes practically no thought at all:

#include <iostream>

using namespace std;

int main()
{
  char words[10][100];
  int i = 0;

  cout<<"Enter a sentence: ";

  while ( i < 10 && cin>> words[i] )
    ++i;

  while ( --i >= 0 )
    cout<< words[i] <<' ';
  cout<<'\n';
}

Thanks a lot for such a precise solution .
But i am a little confused about 2 things

-can we really treat char arrays as integers and use cin>>words[i] (char type)

int a;
like cin>>a

-Secondly if words[10][100] is a 2-d array then can we really use as a single dimensional array like you have used in

cout<<words[i]

Please help !!!

hinduengg 26 Junior Poster in Training

Thank you very much. The solution was great.I understood!!!!!

hinduengg 26 Junior Poster in Training

The first loop of for -understood
but from ---

i=o

i cant understand

if(a[x]==' ')
.
.
.
end

please give a few statements regarding these lines I am unable to get it. the 2-d array is used to tranfser words separately into it

but after that unable to get it specially b[j]==' '
because this array is containg words only right now in for loop

hinduengg 26 Junior Poster in Training

iI cant get the hang of it

the code is the same as above

#include<iostream>
using namespace std;

int main(){

    char a[100];
    int x,m = 0,p;

    cout<<"Enter a sentence"<<endl;
    gets(a);

    for(x=0;a[x]!='\0';x++)
    {
        if(a[x]== ' ')
        {
                   for(p=m;p <= x;p++)
                           cout<<a[p];
                   m = x + 1;//For not writing the space character at the //word's end.
        }

        cout<<endl; 
    }

    for(p = m; p <= x;p++)
         cout<<a[p];
     cout<<m<<"last space charecter";              

    for(int r=m;r>=m;r--)
      cout<<a[p];


}

The word order needs to be reversed .(I know want to know how do we get the space positions from end to beginning.)

FOR EXAMPLE-

if you had -' 'JACK WENT UP' '
0-' '
1-J
2-A
3-C
4-K
5-' '
6-W
7-E
8-N
9-T
10-' '
11-U
12-P
13-' '

I want to print words this way

                                        from 10 position to 13 position
                                        from 5 position to 10 position 
                                        from 0 position to 5 position

I have tried a lot but not got it correct
Please help me in this !!!

hinduengg 26 Junior Poster in Training

Please ,the solution must only include functions related to char type strings or otherwise I will not be able to comprehend .

Well my sir told to transfer the words separately in to the rows of a 2 dimensional array and then print them accordingly,but I am unable to get the hang of it.

Please help.

hinduengg 26 Junior Poster in Training

I am not good at strings . So please could you help me in getting this question right?

The question is -if the user inputted -' 'JACK WENT UP' '
then the output should be -

UP WENT JACK

I tried to reverse the string from the last space position but that is not working but cant get the second last index having a space .

Please please help!!

hinduengg 26 Junior Poster in Training

I Am Sorry For The Trouble

~s.o.s~ commented: No problem. BTW, welcome to Daniweb. :-) +21
hinduengg 26 Junior Poster in Training

Thank you so much for the wonderful solution .
I had been trying so hard to get the correct solution ,THANKS A LOT.

But I have 1 query-
Why gets() is dangerous ,what and how do we use fgets ,I mean is there a special prototype?

hinduengg 26 Junior Poster in Training

JUST REPLACE a WITH 0 IN --for(int x=a-1;x>-=0;x--) THAT YOU COULD ACCESS THE WHOLE LENGTH OF THE STRING

YOU KNOW THAT CHAR ARRAYS ARE ZERO INDEXED THEY START FROM 0 TO (LENGTH -1)

hinduengg 26 Junior Poster in Training

HELLO THIS IS MY FIRST POST.

I WISHED IF ANY ONE COULD HELP IN EXTRACTING WORDS FROM A CHAR ARRAY -STRING

LIKE IF THE SENTENCE INPUTTED BY USER - JACK WENT UP
THEN I NEED TO PRINT THESE WORDS SEPARATELY ON FRESH LINES
OUTPUT-
JACK
WENT
UP


I TRIED THIS BUT THIS IS NOT WORKING

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
char a[100];
int x;
cout<<" enter a sentence";
gets(a);
for(int x=0;a[x]!='\0';x++)
{  
  if(a[x]==' ')
{  
  for(int p=0;p<=x;p++)
   cout<<a[p];

  cout<<endl; }
}
}

the output produced is

JACK
JACK WENT
JACK WENT UP

JUST ONE MORE REQUEST
THE PROGRAM SHOULD BE DONE ONLY BY SIMPLE CHAR TYPE ARRAYS PLEASE.

I HAVE TRIED THIS QUERY ON OTHER FORUMS BUT ALL ADVICED TO USE "STDL "STRINGS WHICH IS NOT IN MY COURSE.

YOU CAN USE MULTIDIMENSIONAL ARRAYS FOR STORING WORDS

HOPING FOR A SOLUTION