package abc;

import java.util.*;

public class TransformCharacters {
    public static String changeCharacters(String string) {
        for (int i = 0; i < string.length(); i++) {
            char ch = string.charAt(i);
            {
                if (Character.isUpperCase(ch))
                    string.replace(ch, '1');
            }

        }
        return string;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String s = "oYoroCoroSor";
        System.out.println(changeCharacters(s));
    }

}

Task was to replace all capital letters with 1.
The logic i used seems fine, but i am not getting the desired output.
the function returns the same string which has been sent to it, I have used Simple print statements at all steps in changeCharacters function, but i am not getting any output on the consloe except the same string whihc I have sent to it.

CREATE TABLE Artist
(
A_id INT NOT NULL,
A_song varchar(100),
A_name varchar(100),
PRIMARY KEY(A_id,A_song)
);
CREATE TABLE Instrument
(
I_id int NOT NULL,
I_keys varchar(100),
I_name varchar(100),
PRIMARY KEY(I_id,I_name),

a_id int NOT NULL,
FOREIGN KEY (a_id) references Artist(A_id)
);

CREATE TABLE Song
(
S_id int NOT NULL PRIMARY KEY,
S_vocalist varchar(100),
S_nom int NOT NULL,

S_name varchar(100),
FOREIGN KEY (S_name) references Artist(A_song),
S_inst varchar(100),
FOREIGN KEY (S_inst) references Instrument(I_name),
a_id int NOT NULL,
FOREIGN KEY (a_id) references Artist(A_id)
);

I am getting this error: "ERROR 1215 (HY000): Cannot add foreign key constraint" probably on this part of the code :

  S_inst varchar(100),
    FOREIGN KEY (S_inst) references Instrument(I_name),

Please solve.

Is there any method by which I can use the same iterator and get desired outputs (could be without hasnext and next methods or loops) ?

In this main class I used a ListIterator variable, hasnext() and next() method to print LIST memebers.
I created litr variable of ListIterator, I performed some functions on the list i.e, sorting(ascending and descending) etc.
I used the same litr variable and a while loop for outputing the list again and again(after making changes in it), this output method works for the first time only, later on it is not showing the desired output.
See attachments for output snapshot. Thanks

public static void main(String args[]) {

                Publisher pub1 = new Publisher("1000", "Smith", 3);
                Publisher pub2 = new Publisher("4001", "Jones", 8);
                Publisher pub3 = new Publisher("9034", "Johnson", 1);

                List publisherList = new LinkedList();

                publisherList.add(pub1);
                publisherList.add(pub2);
                publisherList.add(pub3);

                // Your code here
                System.out.println("Before sorting (number of publications):"
                        + " \n==========================");
                ListIterator litr = publisherList.listIterator(); // Making a
                                                                    // ListIterator to
                                                                    // access list
                                                                    // memebrs
                while (litr.hasNext()) { // Original list (without sort)
                    System.out.println(litr.next());
                }

                Collections.sort(publisherList); // Made a compareTo method to sort
                System.out.println("\nAfter sorting (number of publications):"
                        + " \n==========================");
                while (litr.hasNext()) { // Original list (without sort)
                    System.out.println(litr.next());
                }

                System.out.println("\nBefore sorting (id):"
                        + " \n==========================");
                while (litr.hasNext()) { // Original list (without sort)
                    System.out.println(litr.next());
                }

                Collections.sort(publisherList, Publisher.PublisherComparator);
                System.out.println("\n After sorting (id):"
                        + " \n==========================");
                while (litr.hasNext()) { // Original list (without sort)
                    System.out.println(litr.next());
                }

            }

Create a class Employee with name, Id and salary as data members. Provide appropriate
constructors, set, get and display methods in the class.
In the main program, use a do-while loop to enter data for employees as long as the user
desires and save all data to a file.
Once the user is done with data entry, read the data for employees from the file and
display the information of each employee.

// Lab_13_A.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<string>
#include<fstream>
using namespace std;

class emp
{
private:
    int id,sal;
    string name;
public:
    emp (int i=0,int sa=0,string s=""){id=i;sal=sa;name=s;}
    void set(int i=0,int sa=0,string s=""){id=i;sal=sa;name=s;}
    string getname(){return name;}
    int getid(){return id;}
    int getsal(){return sal;}
    void display()
    {
        cout<<"\nName: "<<name<<endl;
        cout<<"\nID: "<<id<<endl;
        cout<<"\nSalary: "<<sal<<endl;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    int i,s;
    string n;
    char ch;
    ofstream inf("abc.txt");
    emp e;
    do
    {
        cout<<"Enter Name: ";
        cin>>n;
        cout<<"Enter ID: ";
        cin>>i;
        cout<<"Enter Salary: ";
        cin>>s;
        e.set(i,s,n);
        inf.write(reinterpret_cast<char *>(&e),sizeof(e));
        inf.close();
        cout<<"\nWant to add more: ";
        cin>>ch;
    }while(ch!='n');

    ifstream outf("abc.txt");
    while(!outf.eof())
    {
        outf.read(reinterpret_cast<char *>(&e),sizeof(e));
        e.display();
    }
    outf.close();

    getch();
}

The output is wrong.
When I Input more than one record, It shows just the first record in output.
Secondly It shows the same record 2 times, in the output.
Please Help people.
I have ( OOP/C++ ) semester exam in a week and I am very weak in file handling.

Sir (ANCIENT DRAGON) I am a Noob (:P).Now shifting and stuff,i really Don't know how to do that..and Sir you can look at all the coding,its so simple and every thing is easily done !! I really don't know how to do what you said. Please post some piece of code for me !! Thanks

 #include "stdafx.h"
        #include<iostream>
        #include<conio.h>
        #include<string>

        using namespace std;

        //--------------------------------Structures--------------------------------//
        struct datee
        {   
            int month;
            int days;
            int years;
        };
        struct book
        {   
            string bookname;
            string bookpublisher;
            string authorName;
            int copies;
            int price;
            int edition;
            datee date; 
        };

        //---------------------------Function Prototypes----------------------------//
        void titleheader();
        void menu();
        void addbook(book b[],int i);
        void display(book b[],int j);
        void edit(book b[], int a);
        void search(book b[],int a);
        void del (book b[],int a);
        //--------------------------Main Function---------------------------------//
        char op;

        int _tmain(int argc, _TCHAR* argv[])
        {
            book * pt;

            int ch;
            static int a;
            const int size=10;
            book b[size];
            book array[size];
        loop:
            titleheader();
            menu();
            cout<<"\nPress option key to activate the required function: ";
            cin>>ch;
            switch (ch)
            {
            case 1:
                {
                    system("cls");
                    titleheader();
                    cout<<"How many Books do you want to enter: ";
                    cin>>a;
                    for(int i=0;i<a;i++)
                    {
                        cout<<"\n";
                        addbook(b,i);
                    }
                    cout<<endl;
                    system("pause");
                    cin.get();
                    system("cls");
                    goto loop;
                }

            case 2:
                {
                    system("cls");
                    titleheader();
                    for (int j=0;j<a;j++)
                    {
                        cout<<"\n\t\tBook No: "<<j<<"\n"<<endl;
                        display(b,j);
                    }
                    cout<<endl;
                    system("pause");
                    cin.get();  
                    system("cls");
                    goto loop;
                }

            case 3:
                {
                    system("cls");
                    titleheader();
                    edit(b,a);
                    cout<<endl;
                    system("pause");
                    cin.get();
                    system("cls");
                    goto loop;
                }

            case 4:
                {
                    system("cls");
                    titleheader();
                    search (b,a);
                    system("cls");
                    goto loop;
                }

            case 5:
                {
                    system("cls");
                    titleheader();
                    del(b,a);
                    cout<<endl;
                    system("pause");
                    cin.get();
                    system("cls");
                    goto loop;
                }

            case 6:
                {
                    break;
                }

            default :
                {
                    exit (0);
                }
            }

            getch();
        }
        //************************************ END of main() and Functions Bodies are given below. *********************************************\\

        void titleheader()
        {
            cout<<"\n ------------------------------------------------------------------------------ "<<endl;
            cout<<"                         **** Book Store Managment ****                         "<<endl;
            cout<<" ------------------------------------------------------------------------------\n"<<endl;
        }

        void menu()
        {
            cout<<"1). Add a New Book. "<<endl;
            cout<<"2). Display all Records."<<endl; 
            cout<<"3). Edit a Book ...

Sir mike_2000_17..Thankx a lot Sir its Workin !!

Thankx Sir for a great reply.. I have done what you said but when I go fro Displaying Output it say " PRESS ANY KEY TO GO BACK.." ..the file is not showing saved data on display function call !!

        CODE

                    #include "stdafx.h"
                    #include<iostream>
                    #include<conio.h>
                    #include<string>
                    #include<fstream>
                    using namespace std;
                    //---------------------------Function Prototypes----------------------------//
                    void titleheader();
                    void menu();
                    void addbook();
                    void display();
                    //--------------------------Main Function---------------------------------//
                    int _tmain(int argc, _TCHAR* argv[])
                    {
                        int op;
                        titleheader();
                        menu();
                        cout<<"\nPress option key to activate the required function: ";
                        cin>>op;
                        switch (op)
                        {
                        case 1:
                            {
                                system("cls");
                                titleheader();
                                cout<<"\n";
                                addbook();  
                                system ("pause");
                                cin.get();
                                system("cls");
                                break;
                            }
                        case 2:
                            {
                                system("cls");
                                titleheader();
                                display();
                                system ("pause");
                                cin.get();
                                system("cls");
                                break;
                            }
                        default :
                            {
                                exit (0);
                            }
                        }
                        getch();
                    }
                    //************************************ END of main() and Functions Bodies are given below. *********************************************\\
                    void titleheader()
                    {
                        cout<<"\n ------------------------------------------------------------------------------ "<<endl;
                        cout<<"                      **** Book Store Managment ****                             "<<endl;
                        cout<<" ------------------------------------------------------------------------------\n"<<endl;
                    }
                    void menu()
                    {
                        cout<<"1). Add a New Book. "<<endl;
                        cout<<"2). Display all Records. "<<endl; 
                    }
                    void addbook()
                    {
                        string bookname;
                        string publisher;
                        string author;
                        int copies;
                        int price;
                        int edition;
                        ofstream input("abc.txt",ios::app);
                        cout<<"Enter Book name: ";
                        cin>>bookname;
                        cout<<"Enter Book Publisher name: ";
                        cin>>publisher;
                        cout<<"Enter Author/Writer name: ";
                        cin>>author;
                        cout<<"Enter Number of Copies : ";
                        cin>>copies;
                        cout<<"Enter Price: ";
                        cin>>price;
                        cout<<"Enter Edition: " ;
                        cin>>edition;
                        input<<bookname<<publisher<<author<<copies<<price<<edition;
                        input.close();
                    }
                    void display()
                    {
                        ifstream ofile("abc.txt");
                        string bookname;
                        string publisher;
                        string author;
                        int copies;
                        int price;
                        int edition;
                        cout<<" Book Name: "<<bookname<<endl;
                        cout<<" Publisher Name: "<<publisher<<endl;
                        cout<<" Author Name : "<<author<<endl;
                        cout<<" No. Of Copies: "<<copies<<endl;
                        cout<<" Price: "<<price<<endl;
                        cout<<" Book Edition: "<<edition<<endl;
                        while (ofile>>bookname>>publisher>>author>>copies>>price>>edition)
                        {
                            cout<<bookname<<publisher<<author<<copies<<price<<edition;
                        }
                        ofile.close();
                    }
> >     In display Function Ouput comes: 
> 
> 
>    * Book Name:
>     Publisher Name:
>     Author ...

Done so..Runtime Error removed..Now the inputs I am doing in file are getting saved on disk .. but when I print them on screen in display function T,they don't get printed..READING file in display function is not happening !!

CODE

#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<string>
#include<fstream>
using namespace std;

//---------------------------Function Prototypes----------------------------//
void titleheader();
void menu();
void addbook();
void display();

//--------------------------Main Function---------------------------------//

int _tmain(int argc, _TCHAR* argv[])
{
    int op;
    titleheader();
    menu();
    cout<<"\nPress option key to activate the required function: ";
    cin>>op;
    switch (op)
    {
    case 1:
        {
            system("cls");
            titleheader();
            cout<<"\n";
            addbook();  
            system ("pause");
            cin.get();
            system("cls");
            break;
        }

    case 2:
        {
            system("cls");
            titleheader();
            display();
            system ("pause");
            cin.get();
            system("cls");
            break;
        }

    default :
        {
            exit (0);
        }
    }
    getch();
}
//************************************ END of main() and Functions Bodies are given below. *********************************************\\

void titleheader()
{
    cout<<"\n ------------------------------------------------------------------------------ "<<endl;
    cout<<"                      **** Book Store Managment ****                             "<<endl;
    cout<<" ------------------------------------------------------------------------------\n"<<endl;
}
void menu()
{
    cout<<"1). Add a New Book. "<<endl;
    cout<<"2). Display all Records. "<<endl; 
}

void addbook()
{
    string bookname;
    string publisher;
    string author;
    int copies;
    int price;
    int edition;

    ofstream input("abc.txt",ios::app);
    cout<<"Enter Book name: ";
    cin>>bookname;
    cout<<"Enter Book Publisher name: ";
    cin>>publisher;
    cout<<"Enter Author/Writer name: ";
    cin>>author;
    cout<<"Enter Number of Copies : ";
    cin>>copies;
    cout<<"Enter Price: ";
    cin>>price;
    cout<<"Enter Edition: " ;
    cin>>edition;
    input<<bookname<<publisher<<author<<copies<<price<<edition;
    input.close();
}

void display()
{
    ifstream ofile("abc.txt");

    string bookname;
    string publisher;
    string author;
    int copies;
    int price;
    int edition;

    cout<<" Book Name: "<<bookname<<endl;
    cout<<" Publisher Name: "<<publisher<<endl;
    cout<<" Author Name : "<<author<<endl;
    cout<<" No. Of Copies: "<<copies<<endl;
    cout<<" Price: "<<price<<endl;
    cout<<" Book Edition: "<<edition<<endl;

    while (ofile>>bookname>>publisher>>author>>copies>>price>>edition)
    {
        cout<<bookname<<publisher<<author<<copies<<price<<edition;
    }
    ofile.close();
}

First of all I am a beginner at C++ . Whenever I use Display function an error comes up,which says "Run-Time Check Failure #3 - The variable ...