0

No.5 Lab 6_строки

Posted by ေမၿမဳိ့သား on 7:18 AM in
Qus==>> Дана строка слов, разделенных пробелами. Сформируйте строку из неповторяющихся слов, расположив их в алфавитном порядке.

#include "stdafx.h"
#include "iostream"
#include "string"
#include "stdio.h"
#include "conio.h"
#include <sstream>
using namespace std;
void main ()
{
char str[100];
cout<<"Enter ur string: ";
cin.getline(str,100);
cout<<endl;
string ostr;
string temp[20];
string result[20];
string sortresult[20];
int index[20];
int i,j;

int count=0,countt=0;
istringstream iss(str);

while(getline(iss, ostr, ' '))

{
index[count]=0;
temp[count]=ostr;
cout<<temp[count]<<" ";//dar ka pyan yay thar !!
count++;

}

cout<<endl;
for(i=0;i<count;i++)
{
bool add=true;
for(j=i+1;j<count;j++)

if(temp[i].compare(temp[j])==0)
{
//finding index for repeated words
index[j]=1;


}

}
string strchange;
for(i=0;i<count;i++)
if(index[i]!=1)
{
result[i]=temp[i];
cout<<result[i]<<" ";
}
else
countt++; //to count how many times of same words
cout<<endl;
for(i=0;i<count;i++)
{
for(j=i+1;j<count;j++)
{
if(result[i].compare(result[j])>0)
{
strchange=result[j];
result[j]=result[i];
result[i]=strchange;

}

}

}


cout<<"\n Final Sorting results: "<<endl;// dar ka sorting si thar!!
for(i=0;i<count;i++)
if(result[i]!="")
cout<<result[i]<<" ";

getch();
}

 

0

No.5 Lab 5_матрицы

Posted by ေမၿမဳိ့သား on 7:17 AM in
Qus==>> В данной целочисленной матрице 5x7 заменить каждый элемент строки на среднее арифметическое значение этой строки.
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
        int i,j;
        const int row=5,col=7;
        int soe[row][col];
       
        for(i=0;i<row;i++)
        {
                for(j=0;j<col;j++)
                {
                    soe[i][j]=rand()%50+5;
                    cout<<setw(5)<<soe[i][j];
                    //sum=sum+soe[i][j];
                }
                cout<<"\n\n\n";
        }
        //cout<<"\n\n MATRIX ALL's SUM===>>"<<sum;
int moe[20];
int sum=0;
for(i=0;i<row;i++)
{
                for(j=0;j<col;j++)
                {
                        sum=sum+soe[i][j];
                        moe[i]=sum;

                }
                cout<<"EVERY ROW====>>>";
        getch();
    return 0;
}


0

No.5 Lab 5_массивы

Posted by ေမၿမဳိ့သား on 7:15 AM in
Qus==>> В массиве из 20 целых чисел найти сумму и количество чисел, больших введенного с клавиатуры числа и меньших этого же числа.

#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
        int arr[20];
         int sum= 0  , num =0;
         int cnt=0,cnt1=0;
         int cnt2=0;
        for (int i=0; i< 20 ; i++)
        {
            arr[i] = rand() % 30;
            cout << "  " << arr[i] ;
            sum = sum + arr[i] ;
        }

        cout << " \n\n sum " << sum ;
        cout << "\n\n Enter ur number ==> ";
        cin >> num;
       
        for (int i=0; i< 20 ; i++)
        {
                if ( num < arr[i] )
                {cnt++;}
               
                if ( num > arr[i] )
                {cnt1++;}

                 if ( num == arr[i] )
                 {cnt2++;}
        }
        cout << " \n\n greater  count ==> " << cnt ;

        cout << " \n\n snaller count ==> " << cnt1 ;

        cout << " \n\n  similier count ==> " << cnt2 ;
        getch();
        return  0;

}

0

No.5 Lab 4

Posted by ေမၿမဳိ့သား on 12:42 PM in
Qus==>> b) Методом деления отрезка пополам и методом итераций найти
приближенное значение корня уравнения  x4 + 2x3 – x – 1 = 0 на интервале [0, 1]. Абсолютная погрешность не превышает 0.00015. Сравнить методы вычисления.

#include "stdafx.h"
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
void main()
{
    double xt,xg=1.3,eps=0.001,x=5*eps;
    int step=0;
    while(fabs(x)>=eps)
    {
        xt=-0.2*(xg*xg*xg*xg+2*xg*xg*xg-xg-1)+xg;
        x=xt-xg;
        step++;
        xg=xt;
    }
    cout<<"Root equal in row 0,1 is equal \n\n   "<<xt<<endl<<"\n\n and receive in step    "<<step;
    _getch();
}







No.5 Lab 4 a)
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
using namespace std;

void main()
{
    double x,a=0,b=1,y1,y2,eps=0.001,r,l;
    l=a;
    r=b;
    y1=a*a*a*a+2*a*a*a-a-1;
    y2=b*b*b*b+2*b*b*b-b-1;
    int n=0;
    if(y1*y2>0)
    {
        cout<<"No root"<<endl;
        _getch();
        exit(1);
    }
    do
    {
        ++n;
        x=(a+b)/2;
        y1=a*a*a*a+2*a*a*a-a-1;
        y2=x*x*x*x+2*x*x*x-x-1;
        if(y1*y2>0)a=x;
        else b=x;
    }
    while((b-a)>eps);
    x=(a+b)/2;
    cout<<"Root equal in row "<<l<<","<<r<<" equl  "<<x<<endl<<" and receive in step   "<<n;
    cout<<endl;
    _getch();
}

0

No.5 Lab 3

Posted by ေမၿမဳိ့သား on 12:40 PM in
Qus==>> a) Ввести с клавиатуры целое число, которое будет являться количеством целых чисел во вводимой последовательности. Определить максимальное число последовательности и его порядковый номер.

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int i,n,a, max=0, koko=0;

cout << "Enter how many  your loop ==>" ;
cin >> n;
for( i=1;i<=n;i++)
{

     cin>> a;

if (max<a)
{
max= a;
koko = i;
}
}

cout << endl << endl << "\n\nMaximum of that Sequence ==> " << max;
cout << endl << endl << " \n\nLocation ===> " << koko ;
getch();
return 0;

}

Qus ==>>  b) Дано начальное значение =0.5 и рекуррентная формула . Найти номер первого элемента, превысившего введенное с клавиатуры число.
 
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include<math.h>
 using namespace std;
void main()
{
    double n,ans,a=0.5;
    cout <<"enter your number  ";
    cin>>n;
ans=0;
    while(a<n)
    {
        a=1.5*(a+1);
ans=a;

    }
    cout<<"answer = "<<ans;
   
    _getch();
}


Copyright © 2009 ~ ♥ ရည္ညႊန္းရာ ♥ ~ All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.