Showing posts with label CS201. Show all posts
Showing posts with label CS201. Show all posts

Saturday, June 26, 2010

CS201 Assignment # 4 Solution

CS201 Assignment # 4 Solution:
#include


using namespace std;

class Student{

private:

string name;

int rollNumber;

string semester;

double cgpa;



public:

Student(string n,int r,string s,double c )

{name=n;

rollNumber=r;

semester=s;

cgpa=c;

}

Student()

{name="";

rollNumber=0;

semester="Summer 2010";

cgpa=4.0;

}





string get_semester()

{return semester;

}

void set_semester(string n)

{semester=n;

}

void set_roll(int n)

{rollNumber=n;

}

int get_roll()

{return rollNumber;

}

void set_name(string n)

{name=n;

}

string get_name()

{return name;

}

void set_cgpa(double n)

{cgpa=n;

}



double get_cgpa()

{return cgpa;

}

void print()

{cout<<"Student Information\n";

cout<<"Name: "<

cout<<"Roll number: "<

cout<<"Semester: "<

cout<<"Current GPA: "<

}

};



int main()

{Student a;

Student b("name",2345,"Spring 2010",3.5);

a.print();

b.print();

system("pause");

return 0;

}

Tuesday, February 9, 2010

CS201 GDB

CS201 Introduction to Programming GDB Solution

“Although for consistent and reusable design we follow Object Oriented paradigms; “structured approach” has still its worth in some imperative and critical applications. Support or contradict this statement with solid arguments."

Answer:

Help 1

Structured Programming

Structured programming takes on the top-to-bottom approach.It splits the tasks into modular forms. This makes the program simpler and easier to read with less lines and codes.This type of program accomplishes certain tasks for that a specific reason.For example, invoice printers use structured programming. This type has clear, correct, precise descriptions.

Object Oriented Programming

This type of programming uses sections in a program to perform certain tasks.It splits the program into objects that can be reused into other programs.They are small programs that can be used in other software.Each object or module has the data and the instruction of what to do with the data in it. This can be reused in other software directly.

Help 2.

There are advantages as well as disadvantages to using either structured programming languages or object-oriented languages when developing an application. One of the more popular structured programming languages is known as Pascal (Wikipedia – Structured Programming, 2005). Pascal is often used to help teach programming to students in an educational format (Wikipedia – Pascal, 2005). In general terms, a structured programming language is laid out in a series of explicit statements and does not generally contain commands which redirect the execution of statements to other areas of the program (Wikipedia – Pascal, 2005). In comparison, object-oriented languages often contain a set of reusable modular components, which can be called to execute at various points throughout the program, without having to be completely rewritten. Some of the more popular object-oriented languages include Java and C++ (Wikipedia – Object-oriented Programming, 2005). There is an advantage to using structured programming when writing classes and complex functions are not necessary. It can take up more time and energy to develop classes rather than simply write a straightforward piece of code, which executes a specific set of commands. It depends on what the overall purpose of the program is. One of the main disadvantages to using a structured programming language versus an object-oriented language is that it is not ‘modular’. In other words, the code is not split up into reusable sections. The code is written and executed sequentially; therefore you may have redundant code. It may take longer to develop programs using structured language (What Is Object-oriented Programming?, 2000). One of the advantages to using object-oriented programming languages is that it is modular. It is possible to write a reusable piece of code, such as a function or a class, which can be used multiple times throughout a program without having to rewrite it (Cashman, Shelly, & Vermaat, 2004, p. 405). This can save the developer much time and effort in the development process. One of the possible disadvantages to using an object-oriented programming language is its sheer complexity. It is not typically recommended to use object-oriented languages when developing smaller, less complex programs or programs that are built to run on low powered computers (What Is Object-oriented Programming?, 2000).Considering the potential complexity of a filing system application, it would probably be recommended to use object-oriented technology. Also, being that application development using object-oriented languages can be done faster, this might save the developer’s time so that they could deliver the program to the client sooner (Cashman et al., 2004, p. 405).

Sunday, February 7, 2010

CS201

class String
{
private :
char string [ 30 ] ;
public :
String ( )
{
strcpy ( string , "" ) ;
}
void getString ( )
{
cout << "Enter the String : " ;
cin >> string ;
}
void display( )
{
cout << "The String Is : " << string << endl ;
}
// Declaration (prototype) of overloaded sum operator
String operator + ( String & s ) ;
String operator += ( String & s ) ;
};

String String :: operator + ( String &s )
{
String temp; // Declared object temp of String type
strcpy ( temp.string , "" ); // Initialized the temp with empty string
strcat ( temp.string , string ); // Concatenated the driving object’s string to //
temp object
strcat ( temp.string , s.string ); // Concatenated the argument’s string to the
// temp object
return temp; // Returned the temp object
}

String String :: operator += ( String &s )
{
String temp; // Declared object temp of String type
strcpy ( temp.string , "" ); // Initialized the temp with empty string
strcat ( temp.string , string ); // Concatenated the driving object’s string to //
temp object
temp=temp+s;

return temp; // Returned the temp object
}

Tuesday, November 17, 2009

CS201

#include using namespace std; void sort(char array[], int length); int main() { char firstArray[15]; char secondArray[15]; char mergedArray[30]; bool flag = false; int i; int mergedIndex; cout<<"Enter into First Array\n"; fgets(firstArray, sizeof(firstArray), stdin); cout<<"Enter into Second array\n"; fgets(secondArray, sizeof(secondArray), stdin); // Copy the first array into the merged array for(i = 0; firstArray[i] != '\n'; ++i) { mergedArray[i] = firstArray[i]; } mergedIndex = i; //Copy second array into merged array for(i = 0; secondArray[i] != '\n'; ++i) { mergedArray[mergedIndex++] = secondArray[i]; } mergedArray[mergedIndex] = 0; cout<<"\nMerged : "; for(i = 0; i<> { cout< } sort(mergedArray, mergedIndex); cout<<"\nSorted : "; for(i = 0; i<> { cout< } system("PAUSE"); return EXIT_SUCCESS; } void sort(char array[], int length) { int stop = length - 1; for (int i = 0; i <> { for (int j = 0; j <> { if (array[j] > array[j+1]) { char tmp = array[j]; array[j] = array[j+1]; array[j+1] = tmp; } } } }
#include #include #include #include using namespace std; const size_t N = 10; const char space = ' '; void selectionSort(char *, size_t length); void printArray(const char *); int main(int argc, char *argv[]) { string line; string::iterator i; size_t j, k; char *a1 = new char[N], *a2 = new char[N], *merged = new char[N*2]; c << "For arrays A1 and A2, enter up to " <<> "; getline(cin,line); for (i = line.begin(), j = 0; (i != line.end()) && (j <> "; getline(cin,line); for (i = line.begin(), j = 0; (i != line.end()) && (j < j =" 0," k =" 0;" i =" 0;" i =" 0;" min =" i;" j =" i+1;" min =" j;" t =" a[min];"> a h b c u v I j k e A2 > y u d f g k I w q a Merged : a y h b d c f u g v I j w k q e Sorted : a b c d e f g h I j k q u v w y #endif
#include using namespace std; void merge(char[],int, char[],int ,char[],int&); void fill(char[], int&,char[],int,int&); void print(char[],int,string); void input(char[],int,string); void sort(char[],int); bool already(char,char[],int); int main() {char a[10],b[10],c[20]; int asize=10,csize=0,bsize=10; input (a,asize,"array 1"); input (b,bsize,"array 2"); print(a,asize,"Original Array 1"); print(b,bsize,"Original Array 2"); merge(a,asize,b,bsize,c,csize); print(c,csize,"Merged Array"); sort(c,csize); print(c,csize,"Sorted Merged Array"); system("pause"); return 0; } void print(char a[],int n,string mess) {int i; cout< i="0;i" aupto="0,bupto=" turn="0;" turn="=" aupto="=" turn="1;" bupto="=" turn="0;" i="0;i" j="i;j" t="a[i];" i="0;i">>a[i]; } bool already(char a,char c[],int csize) {int i; for(i=0;i if(a==c[i]) return true; return false; }