Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment No. 02 Semester: Spring 2009 CS201: Introduction toProgramming Total

ID: 3610370 • Letter: A

Question

Assignment No. 02
Semester: Spring 2009

CS201: Introduction toProgramming

Total Marks: 20

Due Date:13/04/2009

Instructions

Please read the following instructions carefully beforesubmitting assignment:

It should be clear that your assignment will not get anycredit if:

§        The assignment is submitted after due date.

§        The submitted assignment does not open or file iscorrupt.

§        All types of plagiarism are strictlyprohibited.

Note: You have to upload only.cpp file. Assignment in any other format(extension) will not be accepted. If you will submit codein .doc (Word document) you will get zero marks.

Objective

The objective of this assignment is to provide hands onexperience of using

§         Basicconcepts of C++ language and Programming

§        Conditional statements of C language

§         Functionin c language

§         Stringmanipulation in c++

Guidelines

§         Codeshould be properly aligned and well commented.

§         Followc/c++ rules while writing variables names, function names etc

§         Use onlydev-C++ for this assignment.

Assignment

Problem Statement: Sort String Values in AscendingOrder

You are required to write a program that accepts 5 input stringsfrom the user. After sorting strings into ascending order thestring will be displayed.

Detailed Description:

1. Declare a character type string array.

2. Use for loop

3. Get five string values from the user

4. Sort them in ascending order

5. Display them after sorting

6. Ascending order means string values starting from‘a’ will come first, and then starting from‘b’ and so on.

Sample Output

enter string1 : Muhammad

enter string2 : Abdullah

enter string3 : Usman

enter string4 : Ali

enter string5 : Noureen

Sorted string

Abdullah

Ali

Muhammad

Noureen

Usman

Deadline

Your assignment must be uploaded/submitted on or beforeApril 13, 2009

Assignment No. 02
Semester: Spring 2009

CS201: Introduction toProgramming

Total Marks: 20

Due Date:13/04/2009

Instructions

Please read the following instructions carefully beforesubmitting assignment:

It should be clear that your assignment will not get anycredit if:

§        The assignment is submitted after due date.

§        The submitted assignment does not open or file iscorrupt.

§        All types of plagiarism are strictlyprohibited.

Note: You have to upload only.cpp file. Assignment in any other format(extension) will not be accepted. If you will submit codein .doc (Word document) you will get zero marks.

Objective

The objective of this assignment is to provide hands onexperience of using

§         Basicconcepts of C++ language and Programming

§        Conditional statements of C language

§         Functionin c language

§         Stringmanipulation in c++

Guidelines

§         Codeshould be properly aligned and well commented.

§         Followc/c++ rules while writing variables names, function names etc

§         Use onlydev-C++ for this assignment.

Assignment

Problem Statement: Sort String Values in AscendingOrder

You are required to write a program that accepts 5 input stringsfrom the user. After sorting strings into ascending order thestring will be displayed.

Detailed Description:

1. Declare a character type string array.

2. Use for loop

3. Get five string values from the user

4. Sort them in ascending order

5. Display them after sorting

6. Ascending order means string values starting from‘a’ will come first, and then starting from‘b’ and so on.

Sample Output

enter string1 : Muhammad

enter string2 : Abdullah

enter string3 : Usman

enter string4 : Ali

enter string5 : Noureen

Sorted string

Abdullah

Ali

Muhammad

Noureen

Usman

Deadline

Your assignment must be uploaded/submitted on or beforeApril 13, 2009

Explanation / Answer

//========================================================================//
#include<iostream> #include<conio.h> #include<string> using namespace std;
void swap(string*, int ,int ); void sort(string*);
int main(){    string strings[5];       for(int i=0;i<5;i++)//taking userinput    {    cout<<"Enter String"<<i+1<<":";    cin>>strings[i];          }    sort(strings);//calling sort function            for(int i=0;i<5;i++){//print names    cout<<strings[i]<<endl;    }    cout<<endl;
} //function are defined here void swap(string *str, int i, int j)    {    string temp;    temp = str[i];    str[i] = str[j];    str[j] = temp;    } void sort (string *str)   {    for(int i=0;i<5;i++)    {    for(intj=i+1;j<5;j++)    {      if(str[i].compare(str[j]) >0)      {      swap(str, i, j);      }    }    }   }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote